icydb_core/value/
semantics.rs1use crate::value::{CoercionFamily, CoercionFamilyExt, Value};
8
9#[must_use]
12pub const fn is_numeric(value: &Value) -> bool {
13 matches!(
14 value,
15 Value::Decimal(_)
16 | Value::Duration(_)
17 | Value::Float32(_)
18 | Value::Float64(_)
19 | Value::Int(_)
20 | Value::Int128(_)
21 | Value::Timestamp(_)
22 | Value::Uint(_)
23 | Value::Uint128(_)
24 )
25}
26
27#[must_use]
29pub const fn supports_numeric_coercion(value: &Value) -> bool {
30 matches!(
31 value,
32 Value::Decimal(_)
33 | Value::Duration(_)
34 | Value::Float32(_)
35 | Value::Float64(_)
36 | Value::Int(_)
37 | Value::Int128(_)
38 | Value::Timestamp(_)
39 | Value::Uint(_)
40 | Value::Uint128(_)
41 )
42}
43
44#[must_use]
46pub const fn coercion_family(value: &Value) -> CoercionFamily {
47 match value {
48 Value::Account(_) | Value::Principal(_) | Value::Ulid(_) => CoercionFamily::Identifier,
49 Value::Blob(_) | Value::Subaccount(_) => CoercionFamily::Blob,
50 Value::Bool(_) => CoercionFamily::Bool,
51 Value::Date(_)
52 | Value::Decimal(_)
53 | Value::Duration(_)
54 | Value::Float32(_)
55 | Value::Float64(_)
56 | Value::Int(_)
57 | Value::Int128(_)
58 | Value::IntBig(_)
59 | Value::Timestamp(_)
60 | Value::Uint(_)
61 | Value::Uint128(_)
62 | Value::UintBig(_) => CoercionFamily::Numeric,
63 Value::Enum(_) => CoercionFamily::Enum,
64 Value::List(_) | Value::Map(_) => CoercionFamily::Collection,
65 Value::Null => CoercionFamily::Null,
66 Value::Text(_) => CoercionFamily::Textual,
67 Value::Unit => CoercionFamily::Unit,
68 }
69}
70
71impl Value {
72 #[must_use]
75 pub const fn is_numeric(&self) -> bool {
76 is_numeric(self)
77 }
78
79 #[must_use]
81 pub const fn supports_numeric_coercion(&self) -> bool {
82 supports_numeric_coercion(self)
83 }
84}
85
86impl CoercionFamilyExt for Value {
87 fn coercion_family(&self) -> CoercionFamily {
93 coercion_family(self)
94 }
95}