torrust_tracker_primitives/
pagination.rs1use derive_more::Constructor;
2use serde::Deserialize;
3
4#[derive(Deserialize, Copy, Clone, Debug, PartialEq, Constructor)]
6pub struct Pagination {
7 pub offset: u32,
9 pub limit: u32,
11}
12
13impl Pagination {
14 #[must_use]
15 pub fn new_with_options(offset_option: Option<u32>, limit_option: Option<u32>) -> Self {
16 let offset = match offset_option {
17 Some(offset) => offset,
18 None => Pagination::default_offset(),
19 };
20 let limit = match limit_option {
21 Some(offset) => offset,
22 None => Pagination::default_limit(),
23 };
24
25 Self { offset, limit }
26 }
27
28 #[must_use]
29 pub fn default_offset() -> u32 {
30 0
31 }
32
33 #[must_use]
34 pub fn default_limit() -> u32 {
35 4000
36 }
37}
38
39impl Default for Pagination {
40 fn default() -> Self {
41 Self {
42 offset: Self::default_offset(),
43 limit: Self::default_limit(),
44 }
45 }
46}