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 Float32,
20 Float64,
21 Int,
22 Int128,
23 IntBig,
24 Principal,
25 Subaccount,
26 Text,
27 Timestamp,
28 Uint,
29 Uint128,
30 UintBig,
31 Ulid,
32 Unit,
33}
34
35impl ScalarKind {
36 #[must_use]
38 pub const fn metadata(self) -> ScalarMetadata {
39 scalar_kind_registry!(metadata_from_registry, self)
40 }
41
42 #[must_use]
44 pub const fn coercion_family(self) -> ScalarCoercionFamily {
45 self.metadata().family
46 }
47
48 #[must_use]
50 pub const fn is_numeric_value(self) -> bool {
51 self.metadata().is_numeric_value
52 }
53
54 #[must_use]
56 pub const fn supports_numeric_coercion(self) -> bool {
57 self.metadata().supports_numeric_coercion
58 }
59
60 #[must_use]
62 pub const fn supports_arithmetic(self) -> bool {
63 self.metadata().supports_arithmetic
64 }
65
66 #[must_use]
68 pub const fn supports_equality(self) -> bool {
69 self.metadata().supports_equality
70 }
71
72 #[must_use]
74 pub const fn supports_ordering(self) -> bool {
75 self.metadata().supports_ordering
76 }
77
78 #[must_use]
80 pub const fn is_keyable(self) -> bool {
81 self.metadata().is_keyable
82 }
83
84 #[must_use]
86 pub const fn is_storage_key_encodable(self) -> bool {
87 self.metadata().is_storage_key_encodable
88 }
89}
90
91#[derive(Clone, Copy, Debug, Eq, PartialEq)]
98#[expect(clippy::struct_excessive_bools)]
99pub struct ScalarMetadata {
100 pub family: ScalarCoercionFamily,
101 pub is_numeric_value: bool,
102 pub supports_numeric_coercion: bool,
103 pub supports_arithmetic: bool,
104 pub supports_equality: bool,
105 pub supports_ordering: bool,
106 pub is_keyable: bool,
107 pub is_storage_key_encodable: bool,
108}
109
110#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
117pub enum ScalarCoercionFamily {
118 Numeric,
119 Textual,
120 Identifier,
121 Enum,
122 Blob,
123 Bool,
124 Unit,
125}
126
127pub const ALL_SCALAR_KINDS: [ScalarKind; 21] = scalar_kind_registry!(all_kinds_from_registry);