pub struct Cursor {
pub field: String,
pub value: CursorValue,
pub direction: CursorDirection,
}Fields§
§field: String§value: CursorValue§direction: CursorDirectionImplementations§
Source§impl Cursor
impl Cursor
pub fn new( field: String, value: CursorValue, direction: CursorDirection, ) -> Self
pub fn encode(&self) -> Result<String, String>
pub fn decode(encoded: &str) -> Result<Self, String>
Sourcepub fn value_from_row<T: Serialize>(
field: &str,
row: &T,
template: Option<&CursorValue>,
) -> Result<CursorValue, String>
pub fn value_from_row<T: Serialize>( field: &str, row: &T, template: Option<&CursorValue>, ) -> Result<CursorValue, String>
Read the cursor field out of a serialized row.
The row is serialized with serde_json and field is looked up on the
resulting object. A qualified name such as users.id falls back to its last
segment (id), so cursors on table-qualified columns still resolve. See
CursorValue::from_json for how template shapes the value.
Sourcepub fn from_row<T: Serialize>(
field: impl Into<String>,
row: &T,
direction: CursorDirection,
) -> Result<Self, String>
pub fn from_row<T: Serialize>( field: impl Into<String>, row: &T, direction: CursorDirection, ) -> Result<Self, String>
Build a cursor anchored at row, for example to hand out a next_cursor
from the last row of an offset page:
use paginator_utils::{Cursor, CursorDirection, CursorValue};
use serde::Serialize;
#[derive(Serialize)]
struct User { id: i64, name: String }
let last = User { id: 42, name: "Ada".into() };
let next = Cursor::from_row("id", &last, CursorDirection::After).unwrap();
assert_eq!(next.value, CursorValue::Int(42));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Cursor
impl<'de> Deserialize<'de> for Cursor
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 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
Mutably borrows from an owned value. Read more