use phf::phf_map;
use strum_macros::Display;
#[cfg(feature = "alloc")]
use ::alloc::{borrow::Cow, format, vec, vec::Vec};
#[derive(Clone, Debug, Display, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DecimalType {
#[strum(to_string = "decimal")]
Decimal,
#[strum(to_string = "integer")]
Integer,
#[strum(to_string = "long")]
Long,
#[strum(to_string = "int")]
Int,
#[strum(to_string = "short")]
Short,
#[strum(to_string = "byte")]
Byte,
}
impl DecimalType {
pub fn name(&self) -> &str {
use DecimalType::*;
match self {
Decimal => "decimal",
Integer => "integer",
Long => "long",
Int => "int",
Short => "short",
Byte => "byte",
}
}
pub fn curie(&self) -> &str {
use DecimalType::*;
match self {
Decimal => "xsd:decimal",
Integer => "xsd:integer",
Long => "xsd:long",
Int => "xsd:int",
Short => "xsd:short",
Byte => "xsd:byte",
}
}
#[cfg(feature = "alloc")]
pub fn iri_string(&self) -> Cow<'_, str> {
Cow::Owned(format!("{}{}", crate::BASE_URI, self))
}
pub fn base_type(&self) -> Option<DecimalType> {
use DecimalType::*;
match self {
Decimal => None,
Integer => Some(Decimal),
Long => Some(Integer),
Int => Some(Long),
Short => Some(Int),
Byte => Some(Short),
}
}
#[cfg(feature = "alloc")]
pub fn base_types(&self) -> Vec<DecimalType> {
use DecimalType::*;
match self {
Decimal => vec![],
Integer => vec![Decimal],
Long => vec![Integer, Decimal],
Int => vec![Long, Integer, Decimal],
Short => vec![Int, Long, Integer, Decimal],
Byte => vec![Short, Int, Long, Integer, Decimal],
}
}
}
#[allow(unused)]
static DECIMAL_TYPES: phf::Map<&'static str, DecimalType> = phf_map! {
"decimal" => DecimalType::Decimal,
"integer" => DecimalType::Integer,
"long" => DecimalType::Long,
"int" => DecimalType::Int,
"short" => DecimalType::Short,
"byte" => DecimalType::Byte,
};