use serde::{Deserialize, Serialize};
use std::hash::Hash;
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Default)]
pub enum NullType {
#[default]
Null, NaN, BadData, BadType, ErrOverflow, UnknownProp, DivByZero, OutOfRange, }
impl NullType {
pub fn is_bad(&self) -> bool {
matches!(
self,
NullType::BadData | NullType::BadType | NullType::ErrOverflow | NullType::OutOfRange
)
}
pub fn is_computational_error(&self) -> bool {
matches!(
self,
NullType::NaN | NullType::DivByZero | NullType::ErrOverflow
)
}
pub fn to_string(&self) -> &str {
match self {
NullType::Null => "NULL",
NullType::NaN => "NaN",
NullType::BadData => "BAD_DATA",
NullType::BadType => "BAD_TYPE",
NullType::ErrOverflow => "ERR_OVERFLOW",
NullType::UnknownProp => "UNKNOWN_PROP",
NullType::DivByZero => "DIV_BY_ZERO",
NullType::OutOfRange => "OUT_OF_RANGE",
}
}
}
impl std::fmt::Display for NullType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.to_string())
}
}