pub struct KeysetPaginatedResponse<T> {
pub items: Vec<T>,
pub has_next: bool,
pub has_prev: bool,
pub prev_cursor: Option<String>,
pub next_cursor: Option<String>,
}Expand description
A page of results from a keyset-paginated endpoint.
has_next / has_prev reflect whether further pages exist in each direction.
Cursors for navigation are opaque strings — typically the serialised key of
the first/last item in items.
Requires std or alloc.
Fields§
§items: Vec<T>The items on this page.
has_next: boolWhether a next page exists (there are items after the last item).
has_prev: boolWhether a previous page exists (there are items before the first item).
prev_cursor: Option<String>Opaque cursor pointing to the item just before the first item in items.
Pass this as before to retrieve the previous page.
next_cursor: Option<String>Opaque cursor pointing to the item just after the last item in items.
Pass this as after to retrieve the next page.
Implementations§
Source§impl<T> KeysetPaginatedResponse<T>
impl<T> KeysetPaginatedResponse<T>
Sourcepub fn new(
items: Vec<T>,
has_next: bool,
has_prev: bool,
prev_cursor: Option<String>,
next_cursor: Option<String>,
) -> Self
pub fn new( items: Vec<T>, has_next: bool, has_prev: bool, prev_cursor: Option<String>, next_cursor: Option<String>, ) -> Self
Create a new keyset-paginated response.
§Examples
use api_bones::pagination::KeysetPaginatedResponse;
let resp = KeysetPaginatedResponse::new(
vec![1i32, 2, 3],
true,
false,
None,
Some("cursor_after_3".to_string()),
);
assert!(resp.has_next);
assert!(!resp.has_prev);Sourcepub fn first_page(
items: Vec<T>,
has_next: bool,
next_cursor: Option<String>,
) -> Self
pub fn first_page( items: Vec<T>, has_next: bool, next_cursor: Option<String>, ) -> Self
Convenience: first page with no previous cursor.
§Examples
use api_bones::pagination::KeysetPaginatedResponse;
let resp = KeysetPaginatedResponse::first_page(
vec!["a", "b", "c"],
true,
Some("cursor_after_c".to_string()),
);
assert!(!resp.has_prev);
assert!(resp.has_next);Trait Implementations§
Source§impl<T: Clone> Clone for KeysetPaginatedResponse<T>
impl<T: Clone> Clone for KeysetPaginatedResponse<T>
Source§fn clone(&self) -> KeysetPaginatedResponse<T>
fn clone(&self) -> KeysetPaginatedResponse<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for KeysetPaginatedResponse<T>
impl<T: Debug> Debug for KeysetPaginatedResponse<T>
Source§impl<'de, T> Deserialize<'de> for KeysetPaginatedResponse<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for KeysetPaginatedResponse<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: PartialEq> PartialEq for KeysetPaginatedResponse<T>
impl<T: PartialEq> PartialEq for KeysetPaginatedResponse<T>
Source§impl<T> Serialize for KeysetPaginatedResponse<T>where
T: Serialize,
impl<T> Serialize for KeysetPaginatedResponse<T>where
T: Serialize,
impl<T> StructuralPartialEq for KeysetPaginatedResponse<T>
Auto Trait Implementations§
impl<T> Freeze for KeysetPaginatedResponse<T>
impl<T> RefUnwindSafe for KeysetPaginatedResponse<T>where
T: RefUnwindSafe,
impl<T> Send for KeysetPaginatedResponse<T>where
T: Send,
impl<T> Sync for KeysetPaginatedResponse<T>where
T: Sync,
impl<T> Unpin for KeysetPaginatedResponse<T>where
T: Unpin,
impl<T> UnsafeUnpin for KeysetPaginatedResponse<T>
impl<T> UnwindSafe for KeysetPaginatedResponse<T>where
T: UnwindSafe,
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