icydb_core/db/primitives/limit/
mod.rs

1mod ext;
2
3pub use ext::*;
4
5use crate::{
6    db::query::{QueryError, QueryValidate},
7    traits::EntityKind,
8};
9use candid::CandidType;
10use serde::{Deserialize, Serialize};
11
12///
13/// LimitExpr
14///
15
16#[derive(CandidType, Clone, Debug, Default, Deserialize, Serialize)]
17pub struct LimitExpr {
18    pub limit: Option<u32>,
19    pub offset: u32,
20}
21
22impl LimitExpr {
23    #[must_use]
24    pub const fn new(limit: u32) -> Self {
25        Self {
26            limit: Some(limit),
27            offset: 0,
28        }
29    }
30
31    #[must_use]
32    pub const fn with_offset(limit: u32, offset: u32) -> Self {
33        Self {
34            limit: Some(limit),
35            offset,
36        }
37    }
38
39    #[must_use]
40    pub const fn limit(mut self, limit: u32) -> Self {
41        self.limit = Some(limit);
42        self
43    }
44
45    #[must_use]
46    pub const fn offset(mut self, offset: u32) -> Self {
47        self.offset = offset;
48        self
49    }
50}
51
52impl<E: EntityKind> QueryValidate<E> for LimitExpr {
53    fn validate(&self) -> Result<(), QueryError> {
54        Ok(())
55    }
56}