pub struct CursorPaginated<T> {
pub items: Vec<T>,
pub next_cursor: Option<String>,
pub has_more: bool,
}Expand description
Cursor-based paginated response
§Example
ⓘ
use rustapi_core::{CursorPaginate};
use rustapi_core::hateoas::CursorPaginated;
async fn list_events(cursor: CursorPaginate) -> CursorPaginated<Event> {
let limit = cursor.limit();
let events = db.query_events_after(cursor.after(), limit + 1).await;
let has_more = events.len() > limit as usize;
let items: Vec<Event> = events.into_iter().take(limit as usize).collect();
let next_cursor = items.last().map(|e| e.id.to_string());
CursorPaginated::new(items, next_cursor, has_more)
}Fields§
§items: Vec<T>The items for this page
next_cursor: Option<String>Cursor pointing to the next page (None = no more pages)
has_more: boolWhether there are more items
Implementations§
Trait Implementations§
Source§impl<T: Clone> Clone for CursorPaginated<T>
impl<T: Clone> Clone for CursorPaginated<T>
Source§fn clone(&self) -> CursorPaginated<T>
fn clone(&self) -> CursorPaginated<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for CursorPaginated<T>
impl<T: Debug> Debug for CursorPaginated<T>
Source§impl<T: Serialize + Send> IntoResponse for CursorPaginated<T>
impl<T: Serialize + Send> IntoResponse for CursorPaginated<T>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert self into a Response
Auto Trait Implementations§
impl<T> Freeze for CursorPaginated<T>
impl<T> RefUnwindSafe for CursorPaginated<T>where
T: RefUnwindSafe,
impl<T> Send for CursorPaginated<T>where
T: Send,
impl<T> Sync for CursorPaginated<T>where
T: Sync,
impl<T> Unpin for CursorPaginated<T>where
T: Unpin,
impl<T> UnsafeUnpin for CursorPaginated<T>
impl<T> UnwindSafe for CursorPaginated<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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more