New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sunlightboy opened this Issue Jul 6, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@sunlightboy

sunlightboy commented Jul 6, 2018

  • diesel:

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);
@weiznich

This comment has been minimized.

Contributor

weiznich commented Jul 6, 2018

Could you open a PR for this? The code lives here.
(Hint: the line needs to be let total = results.get(0).map(|(_, total)| total).unwrap_or(0);)

@sunlightboy

This comment has been minimized.

sunlightboy commented Jul 6, 2018

@sunlightboy sunlightboy closed this Jul 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment