Struct PaginationOptions

Source
pub struct PaginationOptions<T = ()>
where T: OrderByOptions,
{ pub page: usize, pub items_per_page: usize, pub order_by: T, }
Expand description

Struct representing pagination options.

§Examples

let options = PaginationOptions::new().page(1).items_per_page(20);

Fields§

§page: usize

Page number.

  • If the value is 0, it will default to 1.
  • If the value exceeds the maximum page number, it will be considered as the maximum page number.

Default: 1.

§items_per_page: usize

Number of items per page.

  • If the value is 0, it means query all items in a single page.

Default: 0.

§order_by: T

Ordering options which has to implement the OrderByOptions trait.

Default: ().

Implementations§

Source§

impl PaginationOptions

Source

pub const fn new() -> PaginationOptions

Create a new PaginationOptions.

let options = PaginationOptions::new();
// equals to
let options = PaginationOptions {
    page:           1,
    items_per_page: 0,
    order_by:       (),
};
Source§

impl<T> PaginationOptions<T>
where T: OrderByOptions,

Source

pub const fn page(self, page: usize) -> PaginationOptions<T>

Set the page number.

  • If the value is 0, it will be considered as 1.
  • If the value exceeds the maximum page number, it will be considered as the maximum page number.
Source

pub const fn items_per_page(self, items_per_page: usize) -> PaginationOptions<T>

Set the number of items per page.

  • If the value is 0, it means query all items in a single page.
Source

pub fn order_by(self, order_by: T) -> PaginationOptions<T>

Set the ordering options which has to implement the OrderByOptions trait.

Source

pub const fn offset(&self) -> u64

Compute the offset for pagination.

Source

pub const fn limit(&self) -> Option<usize>

Compute the limit for pagination. None means unlimited.

Source§

impl<T> PaginationOptions<T>
where T: OrderByOptions,

Source

pub fn to_mysql_limit_offset<'a>(&self, s: &'a mut String) -> &'a str

Generate a LIMIT with OFFSET clause for MySQL.

If limit() is Some(n),

LIMIT <limit()> [OFFSET <offset()>]

If offset() is not zero,

[LIMIT <limit()>] OFFSET <offset()>
Source§

impl<T> PaginationOptions<T>
where T: OrderByOptions,

Source

pub fn to_sqlite_limit_offset<'a>(&self, s: &'a mut String) -> &'a str

Generate a LIMIT with OFFSET clause for SQLite.

If limit() is Some(n),

LIMIT <limit()> [OFFSET <offset()>]

If offset() is not zero,

[LIMIT <limit()>] OFFSET <offset()>

Trait Implementations§

Source§

impl<T> Clone for PaginationOptions<T>
where T: Clone + OrderByOptions,

Source§

fn clone(&self) -> PaginationOptions<T>

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<T> Debug for PaginationOptions<T>
where T: Debug + OrderByOptions,

Source§

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

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

impl<T> Default for PaginationOptions<T>
where T: OrderByOptions,

Source§

fn default() -> PaginationOptions<T>

Create a new PaginationOptions<T>.

let options = <PaginationOptions<()>>::default();
// equals to
let options = PaginationOptions {
    page:           1,
    items_per_page: 0,
    order_by:       (),
};
Source§

impl<'de, T> Deserialize<'de> for PaginationOptions<T>
where T: OrderByOptions + Deserialize<'de>,

Source§

fn deserialize<D>( deserializer: D, ) -> Result<PaginationOptions<T>, <D as Deserializer<'de>>::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Serialize for PaginationOptions<T>

Source§

fn serialize<S>( &self, serializer: S, ) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PaginationOptions<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for PaginationOptions<T>
where T: RefUnwindSafe,

§

impl<T> Send for PaginationOptions<T>
where T: Send,

§

impl<T> Sync for PaginationOptions<T>
where T: Sync,

§

impl<T> Unpin for PaginationOptions<T>
where T: Unpin,

§

impl<T> UnwindSafe for PaginationOptions<T>
where T: 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, 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> 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, 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,