pub struct Page<T> {
pub items: Vec<T>,
pub page: u64,
pub per_page: u64,
pub total_items: u64,
pub total_pages: u64,
}Expand description
A single page of offset-paginated results (LIMIT/OFFSET-style).
Fields§
§items: Vec<T>§page: u641-based page number.
per_page: u64§total_items: u64§total_pages: u640 when total_items is 0; otherwise ceil(total_items / per_page).
Implementations§
Source§impl<T> Page<T>
impl<T> Page<T>
Sourcepub fn new(items: Vec<T>, page: u64, per_page: u64, total_items: u64) -> Self
pub fn new(items: Vec<T>, page: u64, per_page: u64, total_items: u64) -> Self
Builds a page, computing total_pages from total_items and per_page.
page and per_page are clamped to a minimum of 1.
pub fn next_page(&self) -> Option<u64>
pub fn prev_page(&self) -> Option<u64>
Sourcepub fn map<U>(self, f: impl FnMut(T) -> U) -> Page<U>
pub fn map<U>(self, f: impl FnMut(T) -> U) -> Page<U>
Maps items through f, leaving all pagination metadata unchanged —
e.g. to turn a Page<UserRow> into a Page<UserDto> before serializing.
Sourcepub fn link_header(&self, base_url: &str) -> Option<String>
pub fn link_header(&self, base_url: &str) -> Option<String>
Builds an RFC 8288 Link header value with rel="first", "prev",
"next", and "last" entries as applicable (a first page omits
first/prev; a last page omits next/last). page/per_page
query parameters are added to (or overwritten on) base_url, and any
other existing query parameters are preserved.
Returns None if base_url fails to parse, or if there is nothing to
link to (a single page with no prev/next).
Trait Implementations§
impl<T: PartialEq> StructuralPartialEq for Page<T>
Auto Trait Implementations§
impl<T> Freeze for Page<T>
impl<T> RefUnwindSafe for Page<T>where
Vec<T>: RefUnwindSafe,
impl<T> Send for Page<T>
impl<T> Sync for Page<T>
impl<T> Unpin for Page<T>
impl<T> UnsafeUnpin for Page<T>where
Vec<T>: UnsafeUnpin,
impl<T> UnwindSafe for Page<T>where
Vec<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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> ⓘ
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> ⓘ
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