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).