Skip to main content

icydb_model/base/types/
num.rs

1//! Module: base::types::num
2//!
3//! Responsibility: base domain type declarations.
4//! Does not own: runtime storage, query execution, or validator implementation internals.
5//! Boundary: declares macro-modeled domain wrappers and records for downstream schemas.
6
7use crate::prelude::*;
8
9///
10/// Degrees (°)
11///
12
13#[newtype(
14    source_key = "crates/icydb/src/base/types/num.rs::newtype::1",
15    primitive = "Nat16",
16    item(prim = "Nat16"),
17    ty(validator(path = "base::validator::num::Range", args(0, 360)))
18)]
19pub struct Degrees {}
20
21///
22/// Percent
23///
24/// basic percentage as an integer
25///
26
27#[newtype(
28    source_key = "crates/icydb/src/base/types/num.rs::newtype::2",
29    primitive = "Nat8",
30    item(prim = "Nat8"),
31    ty(validator(path = "base::validator::num::Range", args(0, 100)))
32)]
33pub struct Percent {}
34
35///
36/// PercentModifier
37///
38
39#[newtype(
40    source_key = "crates/icydb/src/base/types/num.rs::newtype::3",
41    primitive = "Nat16",
42    item(prim = "Nat16"),
43    ty(validator(path = "base::validator::num::Range", args(0, 10_000)))
44)]
45pub struct PercentModifier {}
46
47///
48/// DecimalRange
49///
50
51#[record(
52    source_key = "crates/icydb/src/base/types/num.rs::record::1",
53    fields(
54        field(
55            source_key = "min",
56            ident = "min",
57            value(item(prim = "Decimal", scale = 18))
58        ),
59        field(
60            source_key = "max",
61            ident = "max",
62            value(item(prim = "Decimal", scale = 18))
63        ),
64    ),
65    traits(remove(ValidateCustom))
66)]
67pub struct DecimalRange {}
68
69impl DecimalRange {
70    #[must_use]
71    pub const fn new(min: Decimal, max: Decimal) -> Self {
72        Self { min, max }
73    }
74}
75
76impl ValidateCustom for DecimalRange {
77    fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
78        let validator = base::validator::num::Lte::new(self.max);
79
80        validator.validate(&self.min, ctx);
81    }
82}
83
84///
85/// DurationRange
86///
87
88#[record(
89    source_key = "crates/icydb/src/base/types/num.rs::record::2",
90    fields(
91        field(source_key = "min", ident = "min", value(item(prim = "Duration"))),
92        field(source_key = "max", ident = "max", value(item(prim = "Duration"))),
93    ),
94    traits(remove(ValidateCustom))
95)]
96pub struct DurationRange {}
97
98impl DurationRange {
99    #[must_use]
100    pub const fn new(min: Duration, max: Duration) -> Self {
101        Self { min, max }
102    }
103}
104
105impl ValidateCustom for DurationRange {
106    fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
107        let validator = base::validator::num::Lte::new(self.max);
108
109        validator.validate(&self.min, ctx);
110    }
111}
112
113///
114/// Int32Range
115///
116
117#[record(
118    source_key = "crates/icydb/src/base/types/num.rs::record::3",
119    fields(
120        field(source_key = "min", ident = "min", value(item(prim = "Int32"))),
121        field(source_key = "max", ident = "max", value(item(prim = "Int32"))),
122    ),
123    traits(remove(ValidateCustom))
124)]
125pub struct Int32Range {}
126
127impl Int32Range {
128    #[must_use]
129    pub const fn new(min: i32, max: i32) -> Self {
130        Self { min, max }
131    }
132}
133
134impl ValidateCustom for Int32Range {
135    fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
136        let validator = base::validator::num::Lte::new(self.max);
137
138        validator.validate(&self.min, ctx);
139    }
140}
141
142///
143/// Nat32Range
144///
145
146#[record(
147    source_key = "crates/icydb/src/base/types/num.rs::record::4",
148    fields(
149        field(source_key = "min", ident = "min", value(item(prim = "Nat32"))),
150        field(source_key = "max", ident = "max", value(item(prim = "Nat32"))),
151    ),
152    traits(remove(ValidateCustom))
153)]
154pub struct Nat32Range {}
155
156impl Nat32Range {
157    #[must_use]
158    pub const fn new(min: u32, max: u32) -> Self {
159        Self { min, max }
160    }
161}
162
163impl ValidateCustom for Nat32Range {
164    fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
165        let validator = base::validator::num::Lte::new(self.max);
166
167        validator.validate(&self.min, ctx);
168    }
169}