Skip to main content

linkrs_core/value/
null.rs

1//! Null Type Definition
2//!
3//! Nebula-Graph-compatible null value type definition.
4
5use serde::{Deserialize, Serialize};
6use std::hash::Hash;
7
8/// Null Type Definition
9///
10/// Nebula-Graph-compatible null value type definition with the following variants:
11/// - **Null**: standard null value
12/// - **NaN**: Non-numeric results
13/// - **BadData**: Bad data (e.g., wrong date format)
14/// - **BadType**: type mismatch error
15/// - **ErrOverflow**: Numeric overflow error
16/// - **UnknownProp**: Unknown property
17/// - **DivByZero**: divide by zero error
18/// - **OutOfRange**: value out of range
19#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
20pub enum NullType {
21    #[default]
22    Null, // Standard null values
23    NaN,         // Non-numeric results
24    BadData,     // Bad data (parsing failure)
25    BadType,     // Type mismatch
26    ErrOverflow, // Numeric overflow
27    UnknownProp, // Unknown property
28    DivByZero,   // Division error
29    OutOfRange,  // Value out of range
30}
31
32impl NullType {
33    pub fn is_bad(&self) -> bool {
34        matches!(
35            self,
36            NullType::BadData | NullType::BadType | NullType::ErrOverflow | NullType::OutOfRange
37        )
38    }
39
40    pub fn is_computational_error(&self) -> bool {
41        matches!(
42            self,
43            NullType::NaN | NullType::DivByZero | NullType::ErrOverflow
44        )
45    }
46
47    pub fn to_string(&self) -> &str {
48        match self {
49            NullType::Null => "NULL",
50            NullType::NaN => "NaN",
51            NullType::BadData => "BAD_DATA",
52            NullType::BadType => "BAD_TYPE",
53            NullType::ErrOverflow => "ERR_OVERFLOW",
54            NullType::UnknownProp => "UNKNOWN_PROP",
55            NullType::DivByZero => "DIV_BY_ZERO",
56            NullType::OutOfRange => "OUT_OF_RANGE",
57        }
58    }
59}
60
61impl std::fmt::Display for NullType {
62    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63        write!(f, "{}", self.to_string())
64    }
65}