pub struct Cursor<T: FromStr + ToString> { /* private fields */ }Expand description
A cursor implementation for use with GraphQL, implements async_graphql::connection::CursorType.
The Cursor consists of a prefix and a ID part. The prefix specifies what kind of object it refers to and the ID specifies which specific object it refers to.
let cursor = Cursor::new("Album", 1);
assert_eq!(cursor.encode_cursor(), "QWxidW06MQ=="); // Album:1Implementations§
Source§impl<T> Cursor<T>
impl<T> Cursor<T>
Sourcepub fn new(prefix: &str, value: T) -> Cursor<T>
pub fn new(prefix: &str, value: T) -> Cursor<T>
Create a new Cursor with the given prefix and value.
This can be used by server implementations to create the appropriate cursor.
Sourcepub fn into_prefix(self, prefix: &str) -> Result<T, CursorError>
pub fn into_prefix(self, prefix: &str) -> Result<T, CursorError>
Deconstruct this cursor into the appropriate ID when its prefix matches.
This function can be used by the server to extract the contained ID. It returns Error when the cursor does not have the specified prefix.
let cursor = Cursor::new("MyPrefix", 10);
assert_eq!(cursor.into_prefix("MyPrefix"), Ok(10));
assert_eq!(cursor.into_prefix("OtherPrefix"), Err(CursorError::InvalidIdentifier));Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Cursor<T>where
T: Freeze,
impl<T> RefUnwindSafe for Cursor<T>where
T: RefUnwindSafe,
impl<T> Send for Cursor<T>where
T: Send,
impl<T> Sync for Cursor<T>where
T: Sync,
impl<T> Unpin for Cursor<T>where
T: Unpin,
impl<T> UnwindSafe for Cursor<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