pub struct PageInfo {
pub has_next: bool,
pub has_prev: bool,
pub next_cursor: Option<String>,
pub prev_cursor: Option<String>,
pub total: Option<u64>,
}Expand description
Page information for paginated responses.
§Example
ⓘ
let page_info = PageInfo::new(items.len(), limit)
.with_next_cursor(next_cursor)
.with_prev_cursor(prev_cursor);
ok!({
"data": items,
"page_info": {
"has_next": page_info.has_next,
"has_prev": page_info.has_prev,
"next_cursor": page_info.next_cursor,
"prev_cursor": page_info.prev_cursor
}
})Fields§
§has_next: boolWhether there are more items after this page.
has_prev: boolWhether there are items before this page.
next_cursor: Option<String>Cursor to fetch the next page.
prev_cursor: Option<String>Cursor to fetch the previous page.
total: Option<u64>Total count (if available).
Implementations§
Source§impl PageInfo
impl PageInfo
Sourcepub fn new(count: usize, limit: usize) -> Self
pub fn new(count: usize, limit: usize) -> Self
Create page info based on returned count vs requested limit.
If count >= limit, assumes there are more items.
Sourcepub fn with_has_prev(self, has_prev: bool) -> Self
pub fn with_has_prev(self, has_prev: bool) -> Self
Set whether there are previous items.
Sourcepub fn with_next_cursor(self, cursor: Option<String>) -> Self
pub fn with_next_cursor(self, cursor: Option<String>) -> Self
Set the next cursor.
Sourcepub fn with_prev_cursor(self, cursor: Option<String>) -> Self
pub fn with_prev_cursor(self, cursor: Option<String>) -> Self
Set the previous cursor.
Sourcepub fn with_total(self, total: u64) -> Self
pub fn with_total(self, total: u64) -> Self
Set the total count.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PageInfo
impl RefUnwindSafe for PageInfo
impl Send for PageInfo
impl Sync for PageInfo
impl Unpin for PageInfo
impl UnwindSafe for PageInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more