Page

Struct Page 

Source
pub struct Page<E> { /* private fields */ }
Expand description

Model to represent paginated items.

§Fields:
  • items: Represents the items in a Page as a Vec of E.
  • 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 be None.
  • next_page: Represents the next page index in a Page. If there is no next page, it will be None.

Implementations§

Source§

impl<E> Page<E>

Source

pub fn get_items(&self) -> &Vec<E>

Get items

Source

pub fn get_page(&self) -> usize

Get page

Source

pub fn get_size(&self) -> usize

Get size

Source

pub fn get_total(&self) -> usize

Get total

Source

pub fn get_pages(&self) -> usize

Get pages

Source

pub fn get_previous_page(&self) -> Option<usize>

Get previous_page

Source

pub fn get_next_page(&self) -> Option<usize>

Get next_page

Source

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, where E must implement Clone.
  • 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<E: Clone> Clone for Page<E>

Source§

fn clone(&self) -> Page<E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E> ComposeSchema for Page<E>
where E: ToSchema,

Source§

impl<E: Debug> Debug for Page<E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E> Default for Page<E>

Implementation of Default for Page.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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.

Source§

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> Display for Page<E>
where E: Debug,

Implementation of Display for Page.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E> IntoIterator for Page<E>

Implementation of IntoIterator for Page.

Source§

type Item = E

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Page<E> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E> Serialize for Page<E>
where E: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<E> ToSchema for Page<E>
where E: ToSchema,

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,