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(validator(path = "base::validator::num::Range", args(0, 360)))
18)]
19pub struct Degrees {}
20
21#[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#[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#[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#[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#[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#[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}