pub struct Pagination { /* private fields */ }Implementations§
Source§impl Pagination
impl Pagination
Sourcepub fn new(page: u32, limit: u32, max_limit: Option<u32>) -> Self
pub fn new(page: u32, limit: u32, max_limit: Option<u32>) -> Self
Create new pagination
max_limit is optional and will be clamped between PAGINATION_MIN_LIMIT and PAGINATION_MAX_LIMIT
§Examples
use api_tools::value_objects::pagination::{Pagination, PAGINATION_MAX_LIMIT, PAGINATION_MIN_LIMIT};
let pagination = Pagination::new(1, 100, None);
assert_eq!(pagination.page(), 1);
assert_eq!(pagination.limit(), 100);
// Invalid page
let pagination = Pagination::new(0, 100, None);
assert_eq!(pagination.page(), 1);
assert_eq!(pagination.limit(), 100);
// Limit too small
let pagination = Pagination::new(2, 10, None);
assert_eq!(pagination.page(), 2);
assert_eq!(pagination.limit(), PAGINATION_MIN_LIMIT);
// Limit too big
let pagination = Pagination::new(2, 1_000, None);
assert_eq!(pagination.page(), 2);
assert_eq!(pagination.limit(), PAGINATION_MAX_LIMIT);
// Limit too big and max limit greater than max
let pagination = Pagination::new(2, 1_000, Some(800));
assert_eq!(pagination.page(), 2);
assert_eq!(pagination.limit(), PAGINATION_MAX_LIMIT);Sourcepub fn set_max_limit(&mut self, max_limit: u32)
pub fn set_max_limit(&mut self, max_limit: u32)
Set a max limit (between PAGINATION_MIN_LIMIT and PAGINATION_MAX_LIMIT)
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 moreSource§impl Debug for Pagination
impl Debug for Pagination
impl Eq 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
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.