forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagination.rs
More file actions
46 lines (40 loc) · 1.1 KB
/
pagination.rs
File metadata and controls
46 lines (40 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use derive_more::Constructor;
use serde::Deserialize;
/// A struct to keep information about the page when results are being paginated
#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Constructor)]
pub struct Pagination {
/// The page number, starting at 0
pub offset: u32,
/// Page size. The number of results per page
pub limit: u32,
}
impl Pagination {
#[must_use]
pub fn new_with_options(offset_option: Option<u32>, limit_option: Option<u32>) -> Self {
let offset = match offset_option {
Some(offset) => offset,
None => Pagination::default_offset(),
};
let limit = match limit_option {
Some(offset) => offset,
None => Pagination::default_limit(),
};
Self { offset, limit }
}
#[must_use]
pub fn default_offset() -> u32 {
0
}
#[must_use]
pub fn default_limit() -> u32 {
4000
}
}
impl Default for Pagination {
fn default() -> Self {
Self {
offset: Self::default_offset(),
limit: Self::default_limit(),
}
}
}