Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Discussion options

You must be logged in to vote

I found a way to do it without a second request. My pagination structure is like this:

pub struct Pagination<T> {
    cursor: Option<Cursor<T>>,
    page_size: u64,
    is_forward: bool,
}

Let's say that is_forward is true: for the very first page, the cursor is set to None (I use id = 0 or name = '' in that case internally). When I navigate forward, then now the cursor is set to something.

  • To know if there is a next page, I query page_size + 1. If there are indeed page_size + 1 results, it means that there is a next page. Then I pop the last result, and use the new last item as cursor.
  • To know if there is a previous page, I look at the cursor and is_forward from the request. If is_forward…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@tyt2y3
Comment options

Answer selected by real-felix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants