xsd_types/value/
mod.rs

1mod any_uri;
2pub mod base64_binary;
3mod boolean;
4mod date;
5mod date_time;
6mod decimal;
7mod double;
8mod duration;
9mod float;
10mod g_day;
11mod g_month;
12mod g_month_day;
13mod g_year;
14mod g_year_month;
15pub mod hex_binary;
16mod q_name;
17mod string;
18mod time;
19
20pub use any_uri::*;
21pub use base64_binary::{Base64Binary, Base64BinaryBuf, InvalidBase64};
22pub use boolean::*;
23pub use date::*;
24pub use date_time::*;
25pub use decimal::*;
26pub use double::*;
27pub use duration::*;
28pub use float::*;
29pub use g_day::*;
30pub use g_month::*;
31pub use g_month_day::*;
32pub use g_year::*;
33pub use g_year_month::*;
34pub use hex_binary::{HexBinary, HexBinaryBuf, InvalidHex};
35pub use q_name::*;
36pub use string::*;
37pub use time::*;
38
39use crate::{Datatype, Value, ValueRef};
40
41pub trait XsdValue {
42	/// Returns the XSD datatype that best describes the value.
43	fn datatype(&self) -> Datatype;
44}
45
46impl From<Value> for std::string::String {
47	fn from(value: Value) -> Self {
48		value.to_string()
49	}
50}
51
52pub enum CowValue<'a> {
53	Borrowed(ValueRef<'a>),
54	Owned(Value),
55}
56
57impl<'a> CowValue<'a> {
58	pub fn as_value_ref(&self) -> ValueRef {
59		match self {
60			Self::Borrowed(v) => *v,
61			Self::Owned(v) => v.as_ref(),
62		}
63	}
64
65	pub fn into_owned(self) -> Value {
66		match self {
67			Self::Borrowed(v) => v.into_owned(),
68			Self::Owned(v) => v,
69		}
70	}
71}
72
73impl<'a> XsdValue for CowValue<'a> {
74	fn datatype(&self) -> Datatype {
75		match self {
76			Self::Borrowed(v) => v.datatype(),
77			Self::Owned(v) => v.datatype(),
78		}
79	}
80}