pub struct Page<T> {
pub items: Vec<T>,
pub next_cursor: Option<String>,
}Expand description
One page of items plus the cursor that fetches the following page.
A next_cursor of None means the caller has reached the end.
Fields§
§items: Vec<T>The rows of this page, already truncated to the requested limit.
next_cursor: Option<String>The encoded cursor for the next page, or None at the end.
Implementations§
Source§impl<T> Page<T>
impl<T> Page<T>
Sourcepub const fn new(items: Vec<T>, next_cursor: Option<String>) -> Self
pub const fn new(items: Vec<T>, next_cursor: Option<String>) -> Self
Creates a page from already truncated items.
Sourcepub fn from_rows<F>(
rows: Vec<T>,
params: &PageParams,
normalized_filters: &F,
key_of: impl FnOnce(&T) -> PageKey<String>,
) -> Result<Self, PaginationError>
pub fn from_rows<F>( rows: Vec<T>, params: &PageParams, normalized_filters: &F, key_of: impl FnOnce(&T) -> PageKey<String>, ) -> Result<Self, PaginationError>
Truncates an over-fetched row set and issues the next cursor.
Fetch PageParams::fetch_limit rows, then hand them here. When more
rows than the limit came back, the extra row is dropped and key_of is
called on the last kept row to build the next cursor.
§Errors
Returns PaginationError::InvalidLimit if the limit does not fit a
usize, or PaginationError::InvalidCursor if the filters cannot be
serialized.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Page<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Page<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
impl<T: Eq> Eq for Page<T>
impl<T: PartialEq> StructuralPartialEq for Page<T>
Auto Trait Implementations§
impl<T> Freeze for Page<T>
impl<T> RefUnwindSafe for Page<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for Page<T>
impl<T> Sync for Page<T>
impl<T> Unpin for Page<T>
impl<T> UnsafeUnpin for Page<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for Page<T>where
Vec<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.