pub struct Cursor(/* private fields */);Expand description
An opaque keyset cursor bound to a version and to the request filters.
Encode with Cursor::encode and read the position back with
Cursor::page_key. The wire form is base64url without padding and must be
treated as opaque by clients.
Implementations§
Source§impl Cursor
impl Cursor
Sourcepub fn from_page_key<F>(
key: &PageKey<String>,
normalized_filters: &F,
) -> Result<Self, PaginationError>
pub fn from_page_key<F>( key: &PageKey<String>, normalized_filters: &F, ) -> Result<Self, PaginationError>
Builds a cursor for a keyset position and the filters it belongs to.
normalized_filters must serialize deterministically. Use a struct with
a fixed field order or a BTreeMap, and normalize values (case, default
ranges) before hashing so an equivalent request keeps its cursor valid.
§Errors
Returns PaginationError::InvalidCursor if the filters cannot be
serialized to JSON.
Sourcepub fn decode<F>(
encoded: &str,
normalized_filters: &F,
) -> Result<Self, PaginationError>
pub fn decode<F>( encoded: &str, normalized_filters: &F, ) -> Result<Self, PaginationError>
Decodes a client cursor and checks it against the current filters.
§Errors
Returns PaginationError::InvalidCursor when the input is not
base64url, is not the expected payload, carries a version this build
does not understand, or was issued for a different filter set.
Sourcepub fn encode(&self) -> Result<String, PaginationError>
pub fn encode(&self) -> Result<String, PaginationError>
Renders the cursor as the base64url string sent to clients.
§Errors
Returns PaginationError::InvalidCursor if the payload cannot be
serialized.
Sourcepub fn page_key<T>(&self) -> Result<PageKey<T>, PaginationError>where
T: FromStr,
pub fn page_key<T>(&self) -> Result<PageKey<T>, PaginationError>where
T: FromStr,
Parses the keyset position back into the ordered column type.
§Errors
Returns PaginationError::InvalidCursor when the stored value does
not parse as T or the tie-breaker is not a UUID.
Trait Implementations§
impl Eq for Cursor
impl StructuralPartialEq for Cursor
Auto Trait Implementations§
impl Freeze for Cursor
impl RefUnwindSafe for Cursor
impl Send for Cursor
impl Sync for Cursor
impl Unpin for Cursor
impl UnsafeUnpin for Cursor
impl UnwindSafe for Cursor
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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
key and return true if they are equal.