icydb_core/value/
family.rs

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