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 to1
. - 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
impl PaginationOptions
Sourcepub const fn new() -> PaginationOptions
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,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub const fn page(self, page: usize) -> PaginationOptions<T>
pub const fn page(self, page: usize) -> PaginationOptions<T>
Set the page number.
- If the value is
0
, it will be considered as1
. - If the value exceeds the maximum page number, it will be considered as the maximum page number.
Sourcepub const fn items_per_page(self, items_per_page: usize) -> PaginationOptions<T>
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.
Sourcepub fn order_by(self, order_by: T) -> PaginationOptions<T>
pub fn order_by(self, order_by: T) -> PaginationOptions<T>
Set the ordering options which has to implement the OrderByOptions
trait.
Source§impl<T> PaginationOptions<T>where
T: OrderByOptions,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub fn to_mysql_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
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,
impl<T> PaginationOptions<T>where
T: OrderByOptions,
Sourcepub fn to_sqlite_limit_offset<'a>(&self, s: &'a mut String) -> &'a str
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,
impl<T> Clone for PaginationOptions<T>where
T: Clone + OrderByOptions,
Source§fn clone(&self) -> PaginationOptions<T>
fn clone(&self) -> PaginationOptions<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T> Debug for PaginationOptions<T>where
T: Debug + OrderByOptions,
impl<T> Debug for PaginationOptions<T>where
T: Debug + OrderByOptions,
Source§impl<T> Default for PaginationOptions<T>where
T: OrderByOptions,
impl<T> Default for PaginationOptions<T>where
T: OrderByOptions,
Source§fn default() -> PaginationOptions<T>
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>,
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>,
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>where
T: OrderByOptions + Serialize,
impl<T> Serialize for PaginationOptions<T>where
T: OrderByOptions + Serialize,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
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> 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