1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! Canonical scalar-kind identities and intrinsic capability metadata.
//!
//! Responsibility: canonical scalar-kind identities and intrinsic capability
//! facts used by the public proposal contract and consumed by runtime policy.
//! Does not own: query coercion decisions, storage encoding, or accepted-schema
//! validation.
//! Boundary: exposes compact scalar-kind capability descriptors and registry order.
use serde::{Deserialize, Serialize};
///
/// ScalarKind
///
/// Canonical scalar kind used for shared capability metadata.
///
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
pub enum ScalarKind {
Account,
Blob,
Bool,
Date,
Decimal,
Duration,
Enum,
Float32,
Float64,
Int,
Int128,
Principal,
Subaccount,
Text,
Timestamp,
Nat,
Nat128,
U256,
Ulid,
Unit,
}
impl ScalarKind {
/// Return the full metadata descriptor for one scalar kind.
#[must_use]
pub const fn metadata(self) -> ScalarMetadata {
scalar_kind_registry!(metadata_from_registry, self)
}
/// Return coercion routing family for this scalar kind.
#[must_use]
pub const fn coercion_family(self) -> ScalarCoercionFamily {
self.metadata().family
}
/// Return whether this scalar participates in numeric-valued classification.
#[must_use]
pub const fn is_numeric_value(self) -> bool {
self.metadata().is_numeric_value
}
/// Return whether this scalar supports numeric widening coercion.
#[must_use]
pub const fn supports_numeric_coercion(self) -> bool {
self.metadata().supports_numeric_coercion
}
/// Return whether this scalar supports arithmetic trait derivation.
#[must_use]
pub const fn supports_arithmetic(self) -> bool {
self.metadata().supports_arithmetic
}
/// Return whether this scalar supports equality predicates.
#[must_use]
pub const fn supports_equality(self) -> bool {
self.metadata().supports_equality
}
/// Return whether this scalar supports ordering predicates.
#[must_use]
pub const fn supports_ordering(self) -> bool {
self.metadata().supports_ordering
}
/// Return whether this scalar is keyable at query/schema level.
#[must_use]
pub const fn is_keyable(self) -> bool {
self.metadata().is_keyable
}
/// Return whether this scalar can be encoded as a storage key.
#[must_use]
pub const fn is_primary_key_component_encodable(self) -> bool {
self.metadata().is_primary_key_component_encodable
}
}
///
/// ScalarMetadata
///
/// Capability metadata shared across schema/core layers.
///
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
#[expect(clippy::struct_excessive_bools)]
pub struct ScalarMetadata {
family: ScalarCoercionFamily,
is_numeric_value: bool,
supports_numeric_coercion: bool,
supports_arithmetic: bool,
supports_equality: bool,
supports_ordering: bool,
is_keyable: bool,
is_primary_key_component_encodable: bool,
}
impl ScalarMetadata {
/// Return coercion routing family for this scalar metadata entry.
#[must_use]
pub const fn family(self) -> ScalarCoercionFamily {
self.family
}
/// Return whether this scalar participates in numeric-valued classification.
#[must_use]
pub const fn is_numeric_value(self) -> bool {
self.is_numeric_value
}
/// Return whether this scalar supports numeric widening coercion.
#[must_use]
pub const fn supports_numeric_coercion(self) -> bool {
self.supports_numeric_coercion
}
/// Return whether this scalar supports arithmetic trait derivation.
#[must_use]
pub const fn supports_arithmetic(self) -> bool {
self.supports_arithmetic
}
/// Return whether this scalar supports equality predicates.
#[must_use]
pub const fn supports_equality(self) -> bool {
self.supports_equality
}
/// Return whether this scalar supports ordering predicates.
#[must_use]
pub const fn supports_ordering(self) -> bool {
self.supports_ordering
}
/// Return whether this scalar is keyable at query/schema level.
#[must_use]
pub const fn is_keyable(self) -> bool {
self.is_keyable
}
/// Return whether this scalar can be encoded as a storage key.
#[must_use]
pub const fn is_primary_key_component_encodable(self) -> bool {
self.is_primary_key_component_encodable
}
}
///
/// ScalarCoercionFamily
///
/// Coarse intrinsic family used by downstream coercion and validation policy.
///
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum ScalarCoercionFamily {
Numeric,
Textual,
Identifier,
Enum,
Blob,
Bool,
Unit,
}
/// Ordered list of all scalar kinds in registry order.
pub const ALL_SCALAR_KINDS: [ScalarKind; 20] = scalar_kind_registry!(all_kinds_from_registry);
#[cfg(test)]
mod tests;