icydb_model/base/types/
num.rs1use crate::prelude::*;
8
9#[newtype(
14 item(prim = "Nat16"),
15 ty(rule(name = "range", numeric_range_inclusive(min = 0, max = 360)))
16)]
17pub struct Degrees {}
18
19#[newtype(
26 item(prim = "Nat8"),
27 ty(rule(name = "range", numeric_range_inclusive(min = 0, max = 100)))
28)]
29pub struct Percent {}
30
31#[newtype(
36 item(prim = "Nat16"),
37 ty(rule(name = "range", numeric_range_inclusive(min = 0, max = 10_000)))
38)]
39pub struct PercentModifier {}
40
41#[record(
46 fields(
47 field(name = "min", value(item(prim = "Decimal", scale = 18))),
48 field(name = "max", value(item(prim = "Decimal", scale = 18))),
49 ),
50 traits(remove(ValidateCustom))
51)]
52pub struct DecimalRange {}
53
54impl DecimalRange {
55 #[must_use]
56 pub const fn new(min: Decimal, max: Decimal) -> Self {
57 Self { min, max }
58 }
59}
60
61impl ValidateCustom for DecimalRange {
62 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
63 let validator = base::validator::num::Lte::new(self.max);
64
65 validator.validate(&self.min, ctx);
66 }
67}
68
69#[record(
74 fields(
75 field(name = "min", value(item(prim = "Duration"))),
76 field(name = "max", value(item(prim = "Duration"))),
77 ),
78 traits(remove(ValidateCustom))
79)]
80pub struct DurationRange {}
81
82impl DurationRange {
83 #[must_use]
84 pub const fn new(min: Duration, max: Duration) -> Self {
85 Self { min, max }
86 }
87}
88
89impl ValidateCustom for DurationRange {
90 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
91 let validator = base::validator::num::Lte::new(self.max);
92
93 validator.validate(&self.min, ctx);
94 }
95}
96
97#[record(
102 fields(
103 field(name = "min", value(item(prim = "Int32"))),
104 field(name = "max", value(item(prim = "Int32"))),
105 ),
106 traits(remove(ValidateCustom))
107)]
108pub struct Int32Range {}
109
110impl Int32Range {
111 #[must_use]
112 pub const fn new(min: i32, max: i32) -> Self {
113 Self { min, max }
114 }
115}
116
117impl ValidateCustom for Int32Range {
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 fields(
131 field(name = "min", value(item(prim = "Nat32"))),
132 field(name = "max", value(item(prim = "Nat32"))),
133 ),
134 traits(remove(ValidateCustom))
135)]
136pub struct Nat32Range {}
137
138impl Nat32Range {
139 #[must_use]
140 pub const fn new(min: u32, max: u32) -> Self {
141 Self { min, max }
142 }
143}
144
145impl ValidateCustom for Nat32Range {
146 fn validate_custom(&self, ctx: &mut dyn VisitorContext) {
147 let validator = base::validator::num::Lte::new(self.max);
148
149 validator.validate(&self.min, ctx);
150 }
151}