1#[macro_use]
2mod macros;
3
4#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
11pub enum ScalarKind {
12 Account,
13 Blob,
14 Bool,
15 Date,
16 Decimal,
17 Duration,
18 Enum,
19 E8s,
20 E18s,
21 Float32,
22 Float64,
23 Int,
24 Int128,
25 IntBig,
26 Principal,
27 Subaccount,
28 Text,
29 Timestamp,
30 Uint,
31 Uint128,
32 UintBig,
33 Ulid,
34 Unit,
35}
36
37impl ScalarKind {
38 #[must_use]
40 pub const fn metadata(self) -> ScalarMetadata {
41 scalar_kind_registry!(metadata_from_registry, self)
42 }
43
44 #[must_use]
46 pub const fn coercion_family(self) -> ScalarCoercionFamily {
47 self.metadata().family
48 }
49
50 #[must_use]
52 pub const fn is_numeric_value(self) -> bool {
53 self.metadata().is_numeric_value
54 }
55
56 #[must_use]
58 pub const fn supports_numeric_coercion(self) -> bool {
59 self.metadata().supports_numeric_coercion
60 }
61
62 #[must_use]
64 pub const fn supports_arithmetic(self) -> bool {
65 self.metadata().supports_arithmetic
66 }
67
68 #[must_use]
70 pub const fn supports_equality(self) -> bool {
71 self.metadata().supports_equality
72 }
73
74 #[must_use]
76 pub const fn supports_ordering(self) -> bool {
77 self.metadata().supports_ordering
78 }
79
80 #[must_use]
82 pub const fn is_keyable(self) -> bool {
83 self.metadata().is_keyable
84 }
85
86 #[must_use]
88 pub const fn is_storage_key_encodable(self) -> bool {
89 self.metadata().is_storage_key_encodable
90 }
91}
92
93#[derive(Clone, Copy, Debug, Eq, PartialEq)]
100#[allow(clippy::struct_excessive_bools)]
101pub struct ScalarMetadata {
102 pub family: ScalarCoercionFamily,
103 pub is_numeric_value: bool,
104 pub supports_numeric_coercion: bool,
105 pub supports_arithmetic: bool,
106 pub supports_equality: bool,
107 pub supports_ordering: bool,
108 pub is_keyable: bool,
109 pub is_storage_key_encodable: bool,
110}
111
112#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
119pub enum ScalarCoercionFamily {
120 Numeric,
121 Textual,
122 Identifier,
123 Enum,
124 Blob,
125 Bool,
126 Unit,
127}
128
129pub const ALL_SCALAR_KINDS: [ScalarKind; 23] = scalar_kind_registry!(all_kinds_from_registry);