Skip to main content

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///
13/// ValueFamily
14/// High-level semantic classification of a `Value`.
15///
16
17#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18pub enum ValueFamily {
19    Numeric,    // Int, Uint, Decimal, Float, Duration, Timestamp, …
20    Textual,    // Text
21    Identifier, // Ulid, Principal, Subaccount
22    Enum,       // Enum(type, variant)
23    Collection, // List
24    Blob,       // Blob(Vec<u8>)
25    Bool,
26    Null, // Value::None
27    Unit, // Value::Unit
28    Unsupported,
29}
30
31impl ValueFamily {
32    #[must_use]
33    pub const fn is_numeric(self) -> bool {
34        matches!(self, Self::Numeric)
35    }
36
37    #[must_use]
38    pub const fn is_textual(self) -> bool {
39        matches!(self, Self::Textual)
40    }
41
42    #[must_use]
43    pub const fn is_identifier(self) -> bool {
44        matches!(self, Self::Identifier)
45    }
46
47    #[must_use]
48    pub const fn is_collection(self) -> bool {
49        matches!(self, Self::Collection)
50    }
51
52    #[must_use]
53    pub const fn is_enum(self) -> bool {
54        matches!(self, Self::Enum)
55    }
56
57    #[must_use]
58    pub const fn is_null(self) -> bool {
59        matches!(self, Self::Null)
60    }
61
62    #[must_use]
63    pub const fn is_scalar(self) -> bool {
64        // scalar = not collection, not unit
65        !self.is_collection() && !matches!(self, Self::Unit)
66    }
67}
68
69///
70/// Extension trait mapping `Value` to `ValueFamily`.
71///
72
73pub trait ValueFamilyExt {
74    fn family(&self) -> ValueFamily;
75}