pub struct Pagination {
pub limit: u32,
pub offset: u32,
}Expand description
Offset/limit pagination parameters parsed from the query string.
Reads the limit and offset query parameters. A missing limit falls back to
Pagination::DEFAULT_LIMIT and a missing offset to 0. limit is clamped to
1..=Pagination::MAX_LIMIT. A non-numeric value rejects the request with a
400 Bad Request carrying code INVALID_QUERY.
Requires the extract feature.
§Example
use axum_api_kit::{ListResponse, Pagination};
use serde::Serialize;
#[derive(Serialize)]
struct Item {
id: u64,
}
async fn list(page: Pagination) -> ListResponse<Item> {
// Query your store using page.limit / page.offset...
let items = vec![Item { id: 1 }];
page.list_response(items, 1)
}Fields§
§limit: u32Maximum number of items to return (clamped to 1..=Pagination::MAX_LIMIT).
offset: u32Zero-based offset of the first item in the page.
Implementations§
Source§impl Pagination
impl Pagination
Sourcepub const DEFAULT_LIMIT: u32 = 50
pub const DEFAULT_LIMIT: u32 = 50
Page size used when the limit query parameter is absent.
Sourcepub const MAX_LIMIT: u32 = 100
pub const MAX_LIMIT: u32 = 100
Largest page size accepted; larger requests are clamped down to this value.
Sourcepub fn list_response<T: Serialize>(
&self,
data: Vec<T>,
total: i64,
) -> ListResponse<T>
pub fn list_response<T: Serialize>( &self, data: Vec<T>, total: i64, ) -> ListResponse<T>
Build a ListResponse for this page from its items and the total match count.
Trait Implementations§
Source§impl Clone for Pagination
impl Clone for Pagination
Source§fn clone(&self) -> Pagination
fn clone(&self) -> Pagination
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for Pagination
Source§impl Debug for Pagination
impl Debug for Pagination
impl Eq for Pagination
Source§impl<S> FromRequestParts<S> for Pagination
impl<S> FromRequestParts<S> for Pagination
Source§impl PartialEq for Pagination
impl PartialEq for Pagination
Source§fn eq(&self, other: &Pagination) -> bool
fn eq(&self, other: &Pagination) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for Pagination
Auto Trait Implementations§
impl Freeze for Pagination
impl RefUnwindSafe for Pagination
impl Send for Pagination
impl Sync for Pagination
impl Unpin for Pagination
impl UnsafeUnpin for Pagination
impl UnwindSafe for Pagination
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.
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