Skip to main content

icydb_primitives/
lib.rs

1#[macro_use]
2mod macros;
3
4///
5/// ScalarKind
6///
7/// Canonical scalar kind used for shared capability metadata.
8///
9
10#[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    /// Return the full metadata descriptor for one scalar kind.
39    #[must_use]
40    pub const fn metadata(self) -> ScalarMetadata {
41        scalar_kind_registry!(metadata_from_registry, self)
42    }
43
44    /// Return coercion routing family for this scalar kind.
45    #[must_use]
46    pub const fn coercion_family(self) -> ScalarCoercionFamily {
47        self.metadata().family
48    }
49
50    /// Return whether this scalar participates in numeric-valued classification.
51    #[must_use]
52    pub const fn is_numeric_value(self) -> bool {
53        self.metadata().is_numeric_value
54    }
55
56    /// Return whether this scalar supports numeric widening coercion.
57    #[must_use]
58    pub const fn supports_numeric_coercion(self) -> bool {
59        self.metadata().supports_numeric_coercion
60    }
61
62    /// Return whether this scalar supports arithmetic trait derivation.
63    #[must_use]
64    pub const fn supports_arithmetic(self) -> bool {
65        self.metadata().supports_arithmetic
66    }
67
68    /// Return whether this scalar supports equality predicates.
69    #[must_use]
70    pub const fn supports_equality(self) -> bool {
71        self.metadata().supports_equality
72    }
73
74    /// Return whether this scalar supports ordering predicates.
75    #[must_use]
76    pub const fn supports_ordering(self) -> bool {
77        self.metadata().supports_ordering
78    }
79
80    /// Return whether this scalar is keyable at query/schema level.
81    #[must_use]
82    pub const fn is_keyable(self) -> bool {
83        self.metadata().is_keyable
84    }
85
86    /// Return whether this scalar can be encoded as a storage key.
87    #[must_use]
88    pub const fn is_storage_key_encodable(self) -> bool {
89        self.metadata().is_storage_key_encodable
90    }
91}
92
93///
94/// ScalarMetadata
95///
96/// Capability metadata shared across schema/core layers.
97///
98
99#[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///
113/// ScalarCoercionFamily
114///
115/// Coarse scalar routing family used by query coercion and validation.
116///
117
118#[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
129/// Ordered list of all scalar kinds in registry order.
130pub const ALL_SCALAR_KINDS: [ScalarKind; 23] = scalar_kind_registry!(all_kinds_from_registry);