pub mod node;
use std::fmt;
use rust_decimal::Decimal;
use crate::quantity::Quantity;
use crate::temporal::{Date, DateTime, Time};
use node::Node;
pub type Collection<'a> = Vec<Item<'a>>;
#[derive(Debug, Clone, PartialEq)]
pub enum Item<'a> {
Boolean(bool),
String(String),
Integer(i64),
Decimal(Decimal),
Date(Date),
DateTime(DateTime),
Time(Time),
Quantity(Quantity),
Node(Node<'a>),
Type(TypeInfo),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TypeInfo {
pub namespace: &'static str,
pub name: Option<String>,
}
pub const SYSTEM_TYPES: [&str; 9] = [
"Any", "Boolean", "String", "Integer", "Decimal", "Date", "DateTime", "Time", "Quantity",
];
impl Item<'_> {
#[must_use]
pub const fn system_type(&self) -> Option<&'static str> {
match self {
Self::Boolean(_) => Some("Boolean"),
Self::String(_) => Some("String"),
Self::Integer(_) => Some("Integer"),
Self::Decimal(_) => Some("Decimal"),
Self::Date(_) => Some("Date"),
Self::DateTime(_) => Some("DateTime"),
Self::Time(_) => Some("Time"),
Self::Quantity(_) => Some("Quantity"),
Self::Node(_) | Self::Type(_) => None,
}
}
#[must_use]
pub const fn as_node(&self) -> Option<&Node<'_>> {
match self {
Self::Node(node) => Some(node),
_ => None,
}
}
}
impl fmt::Display for Item<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Boolean(value) => write!(f, "{value}"),
Self::String(value) => f.write_str(value),
Self::Integer(value) => write!(f, "{value}"),
Self::Decimal(value) => write!(f, "{value}"),
Self::Date(value) => write!(f, "{value}"),
Self::DateTime(value) => write!(f, "{value}"),
Self::Time(value) => write!(f, "{value}"),
Self::Quantity(value) => write!(f, "{value}"),
Self::Node(node) => write!(f, "{node}"),
Self::Type(info) => match &info.name {
Some(name) => write!(f, "{}.{name}", info.namespace),
None => write!(f, "{}.(anonymous)", info.namespace),
},
}
}
}