icydb_model/base/types/
num.rs1use crate::prelude::*;
8
9#[newtype(
14 source_key = "crates/icydb/src/base/types/num.rs::newtype::1",
15 primitive = "Nat16",
16 item(prim = "Nat16"),
17 ty(rule(
18 source_key = "icydb.base.rule.num.degrees.range.v1",
19 kind = "numeric_range_inclusive",
20 args(0, 360)
21 ))
22)]
23pub struct Degrees {}
24
25#[newtype(
32 source_key = "crates/icydb/src/base/types/num.rs::newtype::2",
33 primitive = "Nat8",
34 item(prim = "Nat8"),
35 ty(rule(
36 source_key = "icydb.base.rule.num.percent.range.v1",
37 kind = "numeric_range_inclusive",
38 args(0, 100)
39 ))
40)]
41pub struct Percent {}
42
43#[newtype(
48 source_key = "crates/icydb/src/base/types/num.rs::newtype::3",
49 primitive = "Nat16",
50 item(prim = "Nat16"),
51 ty(rule(
52 source_key = "icydb.base.rule.num.percent_modifier.range.v1",
53 kind = "numeric_range_inclusive",
54 args(0, 10_000)
55 ))
56)]
57pub struct PercentModifier {}
58
59#[record(
64 source_key = "crates/icydb/src/base/types/num.rs::record::1",
65 fields(
66 field(
67 source_key = "min",
68 ident = "min",
69 value(item(prim = "Decimal", scale = 18))
70 ),
71 field(
72 source_key = "max",
73 ident = "max",
74 value(item(prim = "Decimal", scale = 18))
75 ),
76 ),
77 traits(remove(ValidateCustom))
78)]
79pub struct DecimalRange {}
80
81impl DecimalRange {
82 #[must_use]
83 pub const fn new(min: Decimal, max: Decimal) -> Self {
84 Self { min, max }
85 }
86}
87
88impl ValidateCustom for DecimalRange {
89 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
90 let validator = base::validator::num::Lte::new(self.max);
91
92 validator.validate(&self.min, ctx);
93 }
94}
95
96#[record(
101 source_key = "crates/icydb/src/base/types/num.rs::record::2",
102 fields(
103 field(source_key = "min", ident = "min", value(item(prim = "Duration"))),
104 field(source_key = "max", ident = "max", value(item(prim = "Duration"))),
105 ),
106 traits(remove(ValidateCustom))
107)]
108pub struct DurationRange {}
109
110impl DurationRange {
111 #[must_use]
112 pub const fn new(min: Duration, max: Duration) -> Self {
113 Self { min, max }
114 }
115}
116
117impl ValidateCustom for DurationRange {
118 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
119 let validator = base::validator::num::Lte::new(self.max);
120
121 validator.validate(&self.min, ctx);
122 }
123}
124
125#[record(
130 source_key = "crates/icydb/src/base/types/num.rs::record::3",
131 fields(
132 field(source_key = "min", ident = "min", value(item(prim = "Int32"))),
133 field(source_key = "max", ident = "max", value(item(prim = "Int32"))),
134 ),
135 traits(remove(ValidateCustom))
136)]
137pub struct Int32Range {}
138
139impl Int32Range {
140 #[must_use]
141 pub const fn new(min: i32, max: i32) -> Self {
142 Self { min, max }
143 }
144}
145
146impl ValidateCustom for Int32Range {
147 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
148 let validator = base::validator::num::Lte::new(self.max);
149
150 validator.validate(&self.min, ctx);
151 }
152}
153
154#[record(
159 source_key = "crates/icydb/src/base/types/num.rs::record::4",
160 fields(
161 field(source_key = "min", ident = "min", value(item(prim = "Nat32"))),
162 field(source_key = "max", ident = "max", value(item(prim = "Nat32"))),
163 ),
164 traits(remove(ValidateCustom))
165)]
166pub struct Nat32Range {}
167
168impl Nat32Range {
169 #[must_use]
170 pub const fn new(min: u32, max: u32) -> Self {
171 Self { min, max }
172 }
173}
174
175impl ValidateCustom for Nat32Range {
176 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
177 let validator = base::validator::num::Lte::new(self.max);
178
179 validator.validate(&self.min, ctx);
180 }
181}