linkrs_core/value/
null.rs1use serde::{Deserialize, Serialize};
6use std::hash::Hash;
7
8#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
20pub enum NullType {
21 #[default]
22 Null, NaN, BadData, BadType, ErrOverflow, UnknownProp, DivByZero, OutOfRange, }
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}