Cursor

Trait Cursor 

Source
pub trait Cursor {
    type CursorType;

    // Required methods
    fn to_raw_string(&self) -> String;
    fn new(raw: &str, parts: Vec<&str>) -> Result<Self::CursorType, CursorError>;

    // Provided methods
    fn from_encoded_string(input: &str) -> Result<Self::CursorType, CursorError> { ... }
    fn to_encoded_string(&self) -> String { ... }
    fn to_output(&self) -> String { ... }
    fn from_input(input: &str) -> Result<Self::CursorType, Box<str>> { ... }
    fn parse_token<S: ScalarValue>(
        value: ScalarToken<'_>,
    ) -> ParseScalarResult<S> { ... }
}
Expand description

Cursor struct that builds into an opaque string. Cursors are present both in the edges and in the PageInfo within the Connection.

You can implement this trait for your own cursor type if it’s not covered by this library. You can also use the built-in Cursors: - OffsetCursor - StringCursor

This trait implements the common methods needed to be considered a GraphQlScalar which means you can add the following to your struct and it will work out of the box:

#[derive(Debug, GraphQLScalar)]
#[graphql(
    name = "MyCursor",
    to_output_with = Self::to_output,
    from_input_with = Self::from_input
)]
struct MyCursor {}
impl Cursor for MyCursor { ... }

Required Associated Types§

Source

type CursorType

Concrete type of the returned cursor. Usually the thing that implements the trait.

Required Methods§

Source

fn to_raw_string(&self) -> String

Serialize the cursor into a string ready to be base64 encoded.

Source

fn new(raw: &str, parts: Vec<&str>) -> Result<Self::CursorType, CursorError>

Constructor that given the raw string, and a vector of parts (the colon separated segments) will return a Result of the CursorType. Return a CursorError if the decoding fails.

Provided Methods§

Source

fn from_encoded_string(input: &str) -> Result<Self::CursorType, CursorError>

Builds the CursorType from a base64 encoded string. Returns a CursorError if the decoding fails.

Source

fn to_encoded_string(&self) -> String

Builds the base64 encoded variant of the cursor. Uses the url safe alphabet.

Source

fn to_output(&self) -> String

Source

fn from_input(input: &str) -> Result<Self::CursorType, Box<str>>

Source

fn parse_token<S: ScalarValue>(value: ScalarToken<'_>) -> ParseScalarResult<S>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§