icydb_core/value/
family.rs

1//! Semantic classification for `Value`.
2//!
3//! `ValueTag` is a hashing/serialization enum (repr(u8)).
4//! This module adds a *semantic* layer so filter/coercion logic
5//! can decide:
6//!   - which values are numeric
7//!   - which are textual
8//!   - which are identifiers (`Ulid`, `Principal`, etc.)
9//!   - which are collections
10//!
11//! This avoids hardcoding tag comparisons all over the evaluator.
12
13/// High-level semantic classification of a `Value`.
14#[derive(Clone, Copy, Debug, Eq, PartialEq)]
15pub enum ValueFamily {
16    Numeric,    // Int, Uint, Decimal, Float, Duration, Timestamp, …
17    Textual,    // Text
18    Identifier, // Ulid, Principal, Subaccount
19    Enum,       // Enum(type, variant)
20    Collection, // List
21    Blob,       // Blob(Vec<u8>)
22    Bool,
23    Null, // Value::None
24    Unit, // Value::Unit
25    Unsupported,
26}
27
28impl ValueFamily {
29    #[must_use]
30    pub const fn is_numeric(self) -> bool {
31        matches!(self, Self::Numeric)
32    }
33
34    #[must_use]
35    pub const fn is_textual(self) -> bool {
36        matches!(self, Self::Textual)
37    }
38
39    #[must_use]
40    pub const fn is_identifier(self) -> bool {
41        matches!(self, Self::Identifier)
42    }
43
44    #[must_use]
45    pub const fn is_collection(self) -> bool {
46        matches!(self, Self::Collection)
47    }
48
49    #[must_use]
50    pub const fn is_enum(self) -> bool {
51        matches!(self, Self::Enum)
52    }
53
54    #[must_use]
55    pub const fn is_null(self) -> bool {
56        matches!(self, Self::Null)
57    }
58
59    #[must_use]
60    pub const fn is_scalar(self) -> bool {
61        // scalar = not collection, not unit
62        !self.is_collection() && !matches!(self, Self::Unit)
63    }
64}
65
66///
67/// Extension trait mapping `ValueTag → ValueFamily`.
68///
69
70pub trait ValueFamilyExt {
71    fn family(&self) -> ValueFamily;
72}