sgrif / diesel.rs-website

MIT License
32 stars 97 forks source link

I found an error of document on the official guides page. #66

Open leehyong opened 6 years ago

leehyong commented 6 years ago

Problem Description

On official guides the page Using Custom SQL and How to Extend the Query DSL, I found an error of document. See the following:

impl<T> Paginated<T> {
    fn load_and_count_pages<U>(self, conn: &PgConnection) -> QueryResult<(Vec<U>, i64)
    where
        Self: LoadQuery<PgConnection, (U, i64)>,
    {
        let per_page = self.per_page;
        let results = self.load::<(U, i64)>(conn)?;
        let total = results.get(0).map(|(_, total) _total|).unwrap_or(0);
        let records = results.into_iter().map(|(record, _)| record).collect();
        let total_pages = (total as f64 / per_page as f64).ceil() as i64;
        Ok((records, total_pages))
    }
}

The seventh line of the sample code above should be:

 let total = results.get(0).map(|(_, total)| _total).unwrap_or(0);