pub struct Page<E> { /* private fields */ }Expand description
Model to represent paginated items.
§Fields:
- items: Represents the items in a
Pageas aVecofE. - page: Represents the page index in a
Page. It starts from 0 to pages - 1. - size: Represents the maximum number of elements per
Page. items length must be equal to size for all pages except the last page, when items length could be less than or equal to size. - total: Represents the total number of records used for pagination.
- pages: Represents the total number of pages required for paginate the items.
- previous_page: Represents the previous page index in a
Page. If there is no previous page, it will beNone. - next_page: Represents the next page index in a
Page. If there is no next page, it will beNone.
Implementations§
Source§impl<E> Page<E>
impl<E> Page<E>
Sourcepub fn get_previous_page(&self) -> Option<usize>
pub fn get_previous_page(&self) -> Option<usize>
Get previous_page
Sourcepub fn get_next_page(&self) -> Option<usize>
pub fn get_next_page(&self) -> Option<usize>
Get next_page
Sourcepub fn new(
items: &Vec<E>,
page: usize,
size: usize,
total: usize,
) -> PaginationResult<Page<E>>where
E: Clone,
pub fn new(
items: &Vec<E>,
page: usize,
size: usize,
total: usize,
) -> PaginationResult<Page<E>>where
E: Clone,
Create a new Page instance.
§Arguments:
- items: A reference to a collection of items
E, whereEmust implementClone. - page: The page index.
- size: The maximum number of elements per page.
- total: The total number of records used for pagination.
§Returns:
A PaginationResult with a Page if successful, otherwise a PaginationError is returned.
§Example:
use page_hunter::*;
let items: Vec<u32> = vec![1, 2];
let page: usize = 0;
let size: usize = 2;
let total_elements: usize = 5;
let pagination_result: PaginationResult<Page<u32>> = Page::new(
&items,
page,
size,
total_elements,
);
let page: Page<u32> = match pagination_result {
Ok(page) => page,
Err(error) => panic!("Error: {}", error),
};Trait Implementations§
Source§impl<'de, E> Deserialize<'de> for Page<E>where
E: Deserialize<'de>,
Available on crate feature serde only.Implementation of Deserialize for Page if the feature serde is enabled.
impl<'de, E> Deserialize<'de> for Page<E>where
E: Deserialize<'de>,
Available on crate feature
serde only.Implementation of Deserialize for Page if the feature serde is enabled.
Source§fn deserialize<D>(deserializer: D) -> Result<Page<E>, D::Error>where
D: DeDeserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Page<E>, D::Error>where
D: DeDeserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<E> IntoIterator for Page<E>
Implementation of IntoIterator for Page.
impl<E> IntoIterator for Page<E>
Implementation of IntoIterator for Page.
Auto Trait Implementations§
impl<E> Freeze for Page<E>
impl<E> RefUnwindSafe for Page<E>where
E: RefUnwindSafe,
impl<E> Send for Page<E>where
E: Send,
impl<E> Sync for Page<E>where
E: Sync,
impl<E> Unpin for Page<E>where
E: Unpin,
impl<E> UnwindSafe for Page<E>where
E: 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