pub struct Paginated<T> {
pub items: Vec<T>,
pub page: u64,
pub per_page: u64,
pub total: u64,
}Expand description
Paginated response wrapper with metadata and navigation links.
Automatically generates:
- JSON body with
items,meta(page, per_page, total, total_pages), and_links - RFC 8288
Linkresponse headers for first/prev/next/last
§Example
ⓘ
use rustapi_core::{Paginate, Json};
use rustapi_core::hateoas::Paginated;
async fn list_users(paginate: Paginate) -> Paginated<User> {
let users = db.query_users(paginate.offset(), paginate.limit()).await;
let total = db.count_users().await;
paginate.paginate(users, total)
}Fields§
§items: Vec<T>The items for this page
page: u64Current page number (1-indexed)
per_page: u64Items per page
total: u64Total number of items across all pages
Implementations§
Trait Implementations§
Source§impl<T: Serialize + Send> IntoResponse for Paginated<T>
impl<T: Serialize + Send> IntoResponse for Paginated<T>
Source§fn into_response(self) -> Response
fn into_response(self) -> Response
Convert self into a Response
Auto Trait Implementations§
impl<T> Freeze for Paginated<T>
impl<T> RefUnwindSafe for Paginated<T>where
T: RefUnwindSafe,
impl<T> Send for Paginated<T>where
T: Send,
impl<T> Sync for Paginated<T>where
T: Sync,
impl<T> Unpin for Paginated<T>where
T: Unpin,
impl<T> UnsafeUnpin for Paginated<T>
impl<T> UnwindSafe for Paginated<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