ferrobridge_fhirpath/value/
mod.rs1pub mod node;
9
10use std::fmt;
11
12use rust_decimal::Decimal;
13
14use crate::quantity::Quantity;
15use crate::temporal::{Date, DateTime, Time};
16use node::Node;
17
18pub type Collection<'a> = Vec<Item<'a>>;
20
21#[derive(Debug, Clone, PartialEq)]
23pub enum Item<'a> {
24 Boolean(bool),
26 String(String),
28 Integer(i64),
30 Decimal(Decimal),
32 Date(Date),
34 DateTime(DateTime),
36 Time(Time),
38 Quantity(Quantity),
40 Node(Node<'a>),
42 Type(TypeInfo),
44}
45
46#[derive(Debug, Clone, PartialEq, Eq)]
49pub struct TypeInfo {
50 pub namespace: &'static str,
52 pub name: Option<String>,
54}
55
56pub const SYSTEM_TYPES: [&str; 9] = [
58 "Any", "Boolean", "String", "Integer", "Decimal", "Date", "DateTime", "Time", "Quantity",
59];
60
61impl Item<'_> {
62 #[must_use]
65 pub const fn system_type(&self) -> Option<&'static str> {
66 match self {
67 Self::Boolean(_) => Some("Boolean"),
68 Self::String(_) => Some("String"),
69 Self::Integer(_) => Some("Integer"),
70 Self::Decimal(_) => Some("Decimal"),
71 Self::Date(_) => Some("Date"),
72 Self::DateTime(_) => Some("DateTime"),
73 Self::Time(_) => Some("Time"),
74 Self::Quantity(_) => Some("Quantity"),
75 Self::Node(_) | Self::Type(_) => None,
76 }
77 }
78
79 #[must_use]
81 pub const fn as_node(&self) -> Option<&Node<'_>> {
82 match self {
83 Self::Node(node) => Some(node),
84 _ => None,
85 }
86 }
87}
88
89impl fmt::Display for Item<'_> {
90 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91 match self {
92 Self::Boolean(value) => write!(f, "{value}"),
93 Self::String(value) => f.write_str(value),
94 Self::Integer(value) => write!(f, "{value}"),
95 Self::Decimal(value) => write!(f, "{value}"),
96 Self::Date(value) => write!(f, "{value}"),
97 Self::DateTime(value) => write!(f, "{value}"),
98 Self::Time(value) => write!(f, "{value}"),
99 Self::Quantity(value) => write!(f, "{value}"),
100 Self::Node(node) => write!(f, "{node}"),
101 Self::Type(info) => match &info.name {
102 Some(name) => write!(f, "{}.{name}", info.namespace),
103 None => write!(f, "{}.(anonymous)", info.namespace),
104 },
105 }
106 }
107}