xsd_types/
types.rs

1use super::{
2	AnyUri, AnyUriBuf, Base64Binary, Base64BinaryBuf, Boolean, Byte, Date, DateTime, DateTimeStamp,
3	DayTimeDuration, Decimal, Double, Duration, Float, GDay, GMonth, GMonthDay, GYear, GYearMonth,
4	HexBinary, HexBinaryBuf, Id, IdBuf, IdRef, IdRefBuf, Int, Integer, Language, LanguageBuf, Long,
5	NCName, NCNameBuf, NMToken, NMTokenBuf, Name, NameBuf, NegativeInteger, NonNegativeInteger,
6	NonPositiveInteger, NormalizedStr, NormalizedString, PositiveInteger, QName, QNameBuf, Short,
7	Time, Token, TokenBuf, UnsignedByte, UnsignedInt, UnsignedLong, UnsignedShort,
8	YearMonthDuration,
9};
10use crate::{
11	ParseXsd, XsdValue, XSD_ANY_URI, XSD_BASE64_BINARY, XSD_BOOLEAN, XSD_BYTE, XSD_DATE,
12	XSD_DATE_TIME, XSD_DATE_TIME_STAMP, XSD_DAY_TIME_DURATION, XSD_DECIMAL, XSD_DOUBLE,
13	XSD_DURATION, XSD_FLOAT, XSD_G_DAY, XSD_G_MONTH, XSD_G_MONTH_DAY, XSD_G_YEAR, XSD_G_YEAR_MONTH,
14	XSD_HEX_BINARY, XSD_ID, XSD_IDREF, XSD_INT, XSD_INTEGER, XSD_LANGUAGE, XSD_LONG, XSD_NAME,
15	XSD_NC_NAME, XSD_NEGATIVE_INTEGER, XSD_NMTOKEN, XSD_NON_NEGATIVE_INTEGER,
16	XSD_NON_POSITIVE_INTEGER, XSD_NORMALIZED_STRING, XSD_POSITIVE_INTEGER, XSD_Q_NAME, XSD_SHORT,
17	XSD_STRING, XSD_TIME, XSD_TOKEN, XSD_UNSIGNED_BYTE, XSD_UNSIGNED_INT, XSD_UNSIGNED_LONG,
18	XSD_UNSIGNED_SHORT, XSD_YEAR_MONTH_DURATION,
19};
20use iref::Iri;
21use std::fmt;
22/// XSD value parse error.
23#[derive(Debug, thiserror::Error)]
24#[error("XSD value syntax error")]
25pub struct ParseError;
26/// XSD datatype (primitive or not).
27#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
28pub enum Datatype {
29	Boolean,
30	Float,
31	Double,
32	Decimal(DecimalDatatype),
33	String(StringDatatype),
34	Duration(DurationDatatype),
35	DateTime(DateTimeDatatype),
36	Time,
37	Date,
38	GYearMonth,
39	GYear,
40	GMonthDay,
41	GDay,
42	GMonth,
43	Base64Binary,
44	HexBinary,
45	AnyUri,
46	QName,
47}
48impl Datatype {
49	pub fn from_iri(iri: &Iri) -> Option<Self> {
50		if iri == XSD_BOOLEAN {
51			return Some(Self::Boolean);
52		}
53		if iri == XSD_FLOAT {
54			return Some(Self::Float);
55		}
56		if iri == XSD_DOUBLE {
57			return Some(Self::Double);
58		}
59		if let Some(t) = DecimalDatatype::from_iri(iri) {
60			return Some(Self::Decimal(t));
61		}
62		if let Some(t) = StringDatatype::from_iri(iri) {
63			return Some(Self::String(t));
64		}
65		if let Some(t) = DurationDatatype::from_iri(iri) {
66			return Some(Self::Duration(t));
67		}
68		if let Some(t) = DateTimeDatatype::from_iri(iri) {
69			return Some(Self::DateTime(t));
70		}
71		if iri == XSD_TIME {
72			return Some(Self::Time);
73		}
74		if iri == XSD_DATE {
75			return Some(Self::Date);
76		}
77		if iri == XSD_G_YEAR_MONTH {
78			return Some(Self::GYearMonth);
79		}
80		if iri == XSD_G_YEAR {
81			return Some(Self::GYear);
82		}
83		if iri == XSD_G_MONTH_DAY {
84			return Some(Self::GMonthDay);
85		}
86		if iri == XSD_G_DAY {
87			return Some(Self::GDay);
88		}
89		if iri == XSD_G_MONTH {
90			return Some(Self::GMonth);
91		}
92		if iri == XSD_BASE64_BINARY {
93			return Some(Self::Base64Binary);
94		}
95		if iri == XSD_HEX_BINARY {
96			return Some(Self::HexBinary);
97		}
98		if iri == XSD_ANY_URI {
99			return Some(Self::AnyUri);
100		}
101		if iri == XSD_Q_NAME {
102			return Some(Self::QName);
103		}
104		None
105	}
106	pub fn iri(&self) -> &'static Iri {
107		match self {
108			Self::Boolean => XSD_BOOLEAN,
109			Self::Float => XSD_FLOAT,
110			Self::Double => XSD_DOUBLE,
111			Self::Decimal(t) => t.iri(),
112			Self::String(t) => t.iri(),
113			Self::Duration(t) => t.iri(),
114			Self::DateTime(t) => t.iri(),
115			Self::Time => XSD_TIME,
116			Self::Date => XSD_DATE,
117			Self::GYearMonth => XSD_G_YEAR_MONTH,
118			Self::GYear => XSD_G_YEAR,
119			Self::GMonthDay => XSD_G_MONTH_DAY,
120			Self::GDay => XSD_G_DAY,
121			Self::GMonth => XSD_G_MONTH,
122			Self::Base64Binary => XSD_BASE64_BINARY,
123			Self::HexBinary => XSD_HEX_BINARY,
124			Self::AnyUri => XSD_ANY_URI,
125			Self::QName => XSD_Q_NAME,
126		}
127	}
128	pub fn parse(&self, value: &str) -> Result<Value, ParseError> {
129		match self {
130			Self::Boolean => ParseXsd::parse_xsd(value)
131				.map(Value::Boolean)
132				.map_err(|_| ParseError),
133			Self::Float => ParseXsd::parse_xsd(value)
134				.map(Value::Float)
135				.map_err(|_| ParseError),
136			Self::Double => ParseXsd::parse_xsd(value)
137				.map(Value::Double)
138				.map_err(|_| ParseError),
139			Self::Decimal(t) => t.parse(value).map(Into::into),
140			Self::String(t) => t.parse(value).map(Into::into),
141			Self::Duration(t) => t.parse(value).map(Into::into),
142			Self::DateTime(t) => t.parse(value).map(Into::into),
143			Self::Time => ParseXsd::parse_xsd(value)
144				.map(Value::Time)
145				.map_err(|_| ParseError),
146			Self::Date => ParseXsd::parse_xsd(value)
147				.map(Value::Date)
148				.map_err(|_| ParseError),
149			Self::GYearMonth => ParseXsd::parse_xsd(value)
150				.map(Value::GYearMonth)
151				.map_err(|_| ParseError),
152			Self::GYear => ParseXsd::parse_xsd(value)
153				.map(Value::GYear)
154				.map_err(|_| ParseError),
155			Self::GMonthDay => ParseXsd::parse_xsd(value)
156				.map(Value::GMonthDay)
157				.map_err(|_| ParseError),
158			Self::GDay => ParseXsd::parse_xsd(value)
159				.map(Value::GDay)
160				.map_err(|_| ParseError),
161			Self::GMonth => ParseXsd::parse_xsd(value)
162				.map(Value::GMonth)
163				.map_err(|_| ParseError),
164			Self::Base64Binary => ParseXsd::parse_xsd(value)
165				.map(Value::Base64Binary)
166				.map_err(|_| ParseError),
167			Self::HexBinary => ParseXsd::parse_xsd(value)
168				.map(Value::HexBinary)
169				.map_err(|_| ParseError),
170			Self::AnyUri => ParseXsd::parse_xsd(value)
171				.map(Value::AnyUri)
172				.map_err(|_| ParseError),
173			Self::QName => ParseXsd::parse_xsd(value)
174				.map(Value::QName)
175				.map_err(|_| ParseError),
176		}
177	}
178}
179/// [`Decimal`] datatype variants.
180#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
181pub enum DecimalDatatype {
182	Decimal,
183	Integer(IntegerDatatype),
184}
185impl DecimalDatatype {
186	pub fn from_iri(iri: &Iri) -> Option<Self> {
187		if iri == XSD_DECIMAL {
188			return Some(Self::Decimal);
189		}
190		if let Some(t) = IntegerDatatype::from_iri(iri) {
191			return Some(Self::Integer(t));
192		}
193		None
194	}
195	pub fn iri(&self) -> &'static Iri {
196		match self {
197			Self::Decimal => XSD_DECIMAL,
198			Self::Integer(t) => t.iri(),
199		}
200	}
201	pub fn parse(&self, value: &str) -> Result<DecimalValue, ParseError> {
202		match self {
203			Self::Decimal => ParseXsd::parse_xsd(value)
204				.map(DecimalValue::Decimal)
205				.map_err(|_| ParseError),
206			Self::Integer(t) => t.parse(value).map(Into::into),
207		}
208	}
209}
210impl From<IntegerDatatype> for DecimalDatatype {
211	fn from(value: IntegerDatatype) -> Self {
212		Self::Integer(value)
213	}
214}
215impl From<NonPositiveIntegerDatatype> for DecimalDatatype {
216	fn from(value: NonPositiveIntegerDatatype) -> Self {
217		Self::Integer(IntegerDatatype::NonPositiveInteger(value))
218	}
219}
220impl From<NonNegativeIntegerDatatype> for DecimalDatatype {
221	fn from(value: NonNegativeIntegerDatatype) -> Self {
222		Self::Integer(IntegerDatatype::NonNegativeInteger(value))
223	}
224}
225impl From<UnsignedLongDatatype> for DecimalDatatype {
226	fn from(value: UnsignedLongDatatype) -> Self {
227		Self::Integer(IntegerDatatype::NonNegativeInteger(
228			NonNegativeIntegerDatatype::UnsignedLong(value),
229		))
230	}
231}
232impl From<UnsignedIntDatatype> for DecimalDatatype {
233	fn from(value: UnsignedIntDatatype) -> Self {
234		Self::Integer(IntegerDatatype::NonNegativeInteger(
235			NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(value)),
236		))
237	}
238}
239impl From<UnsignedShortDatatype> for DecimalDatatype {
240	fn from(value: UnsignedShortDatatype) -> Self {
241		Self::Integer(IntegerDatatype::NonNegativeInteger(
242			NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
243				UnsignedIntDatatype::UnsignedShort(value),
244			)),
245		))
246	}
247}
248impl From<LongDatatype> for DecimalDatatype {
249	fn from(value: LongDatatype) -> Self {
250		Self::Integer(IntegerDatatype::Long(value))
251	}
252}
253impl From<IntDatatype> for DecimalDatatype {
254	fn from(value: IntDatatype) -> Self {
255		Self::Integer(IntegerDatatype::Long(LongDatatype::Int(value)))
256	}
257}
258impl From<ShortDatatype> for DecimalDatatype {
259	fn from(value: ShortDatatype) -> Self {
260		Self::Integer(IntegerDatatype::Long(LongDatatype::Int(
261			IntDatatype::Short(value),
262		)))
263	}
264}
265impl TryFrom<DecimalDatatype> for IntegerDatatype {
266	type Error = DecimalDatatype;
267	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
268		match value {
269			DecimalDatatype::Integer(value) => Ok(value),
270			other => Err(other),
271		}
272	}
273}
274impl TryFrom<DecimalDatatype> for NonPositiveIntegerDatatype {
275	type Error = DecimalDatatype;
276	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
277		match value {
278			DecimalDatatype::Integer(IntegerDatatype::NonPositiveInteger(value)) => Ok(value),
279			other => Err(other),
280		}
281	}
282}
283impl TryFrom<DecimalDatatype> for NonNegativeIntegerDatatype {
284	type Error = DecimalDatatype;
285	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
286		match value {
287			DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(value)) => Ok(value),
288			other => Err(other),
289		}
290	}
291}
292impl TryFrom<DecimalDatatype> for UnsignedLongDatatype {
293	type Error = DecimalDatatype;
294	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
295		match value {
296			DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
297				NonNegativeIntegerDatatype::UnsignedLong(value),
298			)) => Ok(value),
299			other => Err(other),
300		}
301	}
302}
303impl TryFrom<DecimalDatatype> for UnsignedIntDatatype {
304	type Error = DecimalDatatype;
305	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
306		match value {
307			DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
308				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(value)),
309			)) => Ok(value),
310			other => Err(other),
311		}
312	}
313}
314impl TryFrom<DecimalDatatype> for UnsignedShortDatatype {
315	type Error = DecimalDatatype;
316	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
317		match value {
318			DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
319				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
320					UnsignedIntDatatype::UnsignedShort(value),
321				)),
322			)) => Ok(value),
323			other => Err(other),
324		}
325	}
326}
327impl TryFrom<DecimalDatatype> for LongDatatype {
328	type Error = DecimalDatatype;
329	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
330		match value {
331			DecimalDatatype::Integer(IntegerDatatype::Long(value)) => Ok(value),
332			other => Err(other),
333		}
334	}
335}
336impl TryFrom<DecimalDatatype> for IntDatatype {
337	type Error = DecimalDatatype;
338	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
339		match value {
340			DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(value))) => Ok(value),
341			other => Err(other),
342		}
343	}
344}
345impl TryFrom<DecimalDatatype> for ShortDatatype {
346	type Error = DecimalDatatype;
347	fn try_from(value: DecimalDatatype) -> Result<Self, DecimalDatatype> {
348		match value {
349			DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(
350				IntDatatype::Short(value),
351			))) => Ok(value),
352			other => Err(other),
353		}
354	}
355}
356/// [`str`] datatype variants.
357#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
358pub enum StringDatatype {
359	String,
360	NormalizedString(NormalizedStringDatatype),
361}
362impl StringDatatype {
363	pub fn from_iri(iri: &Iri) -> Option<Self> {
364		if iri == XSD_STRING {
365			return Some(Self::String);
366		}
367		if let Some(t) = NormalizedStringDatatype::from_iri(iri) {
368			return Some(Self::NormalizedString(t));
369		}
370		None
371	}
372	pub fn iri(&self) -> &'static Iri {
373		match self {
374			Self::String => XSD_STRING,
375			Self::NormalizedString(t) => t.iri(),
376		}
377	}
378	pub fn parse(&self, value: &str) -> Result<StringValue, ParseError> {
379		match self {
380			Self::String => ParseXsd::parse_xsd(value)
381				.map(StringValue::String)
382				.map_err(|_| ParseError),
383			Self::NormalizedString(t) => t.parse(value).map(Into::into),
384		}
385	}
386}
387impl From<NormalizedStringDatatype> for StringDatatype {
388	fn from(value: NormalizedStringDatatype) -> Self {
389		Self::NormalizedString(value)
390	}
391}
392impl From<TokenDatatype> for StringDatatype {
393	fn from(value: TokenDatatype) -> Self {
394		Self::NormalizedString(NormalizedStringDatatype::Token(value))
395	}
396}
397impl From<NameDatatype> for StringDatatype {
398	fn from(value: NameDatatype) -> Self {
399		Self::NormalizedString(NormalizedStringDatatype::Token(TokenDatatype::Name(value)))
400	}
401}
402impl From<NCNameDatatype> for StringDatatype {
403	fn from(value: NCNameDatatype) -> Self {
404		Self::NormalizedString(NormalizedStringDatatype::Token(TokenDatatype::Name(
405			NameDatatype::NCName(value),
406		)))
407	}
408}
409impl TryFrom<StringDatatype> for NormalizedStringDatatype {
410	type Error = StringDatatype;
411	fn try_from(value: StringDatatype) -> Result<Self, StringDatatype> {
412		match value {
413			StringDatatype::NormalizedString(value) => Ok(value),
414			other => Err(other),
415		}
416	}
417}
418impl TryFrom<StringDatatype> for TokenDatatype {
419	type Error = StringDatatype;
420	fn try_from(value: StringDatatype) -> Result<Self, StringDatatype> {
421		match value {
422			StringDatatype::NormalizedString(NormalizedStringDatatype::Token(value)) => Ok(value),
423			other => Err(other),
424		}
425	}
426}
427impl TryFrom<StringDatatype> for NameDatatype {
428	type Error = StringDatatype;
429	fn try_from(value: StringDatatype) -> Result<Self, StringDatatype> {
430		match value {
431			StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
432				TokenDatatype::Name(value),
433			)) => Ok(value),
434			other => Err(other),
435		}
436	}
437}
438impl TryFrom<StringDatatype> for NCNameDatatype {
439	type Error = StringDatatype;
440	fn try_from(value: StringDatatype) -> Result<Self, StringDatatype> {
441		match value {
442			StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
443				TokenDatatype::Name(NameDatatype::NCName(value)),
444			)) => Ok(value),
445			other => Err(other),
446		}
447	}
448}
449/// [`Duration`] datatype variants.
450#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
451pub enum DurationDatatype {
452	Duration,
453	DayTimeDuration,
454	YearMonthDuration,
455}
456impl DurationDatatype {
457	pub fn from_iri(iri: &Iri) -> Option<Self> {
458		if iri == XSD_DURATION {
459			return Some(Self::Duration);
460		}
461		if iri == XSD_DAY_TIME_DURATION {
462			return Some(Self::DayTimeDuration);
463		}
464		if iri == XSD_YEAR_MONTH_DURATION {
465			return Some(Self::YearMonthDuration);
466		}
467		None
468	}
469	pub fn iri(&self) -> &'static Iri {
470		match self {
471			Self::Duration => XSD_DURATION,
472			Self::DayTimeDuration => XSD_DAY_TIME_DURATION,
473			Self::YearMonthDuration => XSD_YEAR_MONTH_DURATION,
474		}
475	}
476	pub fn parse(&self, value: &str) -> Result<DurationValue, ParseError> {
477		match self {
478			Self::Duration => ParseXsd::parse_xsd(value)
479				.map(DurationValue::Duration)
480				.map_err(|_| ParseError),
481			Self::DayTimeDuration => ParseXsd::parse_xsd(value)
482				.map(DurationValue::DayTimeDuration)
483				.map_err(|_| ParseError),
484			Self::YearMonthDuration => ParseXsd::parse_xsd(value)
485				.map(DurationValue::YearMonthDuration)
486				.map_err(|_| ParseError),
487		}
488	}
489}
490/// [`DateTime`] datatype variants.
491#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
492pub enum DateTimeDatatype {
493	DateTime,
494	DateTimeStamp,
495}
496impl DateTimeDatatype {
497	pub fn from_iri(iri: &Iri) -> Option<Self> {
498		if iri == XSD_DATE_TIME {
499			return Some(Self::DateTime);
500		}
501		if iri == XSD_DATE_TIME_STAMP {
502			return Some(Self::DateTimeStamp);
503		}
504		None
505	}
506	pub fn iri(&self) -> &'static Iri {
507		match self {
508			Self::DateTime => XSD_DATE_TIME,
509			Self::DateTimeStamp => XSD_DATE_TIME_STAMP,
510		}
511	}
512	pub fn parse(&self, value: &str) -> Result<DateTimeValue, ParseError> {
513		match self {
514			Self::DateTime => ParseXsd::parse_xsd(value)
515				.map(DateTimeValue::DateTime)
516				.map_err(|_| ParseError),
517			Self::DateTimeStamp => ParseXsd::parse_xsd(value)
518				.map(DateTimeValue::DateTimeStamp)
519				.map_err(|_| ParseError),
520		}
521	}
522}
523/// Any XSD value.
524#[derive(Debug, Clone)]
525pub enum Value {
526	Boolean(Boolean),
527	Float(Float),
528	Double(Double),
529	Decimal(Decimal),
530	Integer(Integer),
531	NonPositiveInteger(NonPositiveInteger),
532	NegativeInteger(NegativeInteger),
533	NonNegativeInteger(NonNegativeInteger),
534	PositiveInteger(PositiveInteger),
535	UnsignedLong(UnsignedLong),
536	UnsignedInt(UnsignedInt),
537	UnsignedShort(UnsignedShort),
538	UnsignedByte(UnsignedByte),
539	Long(Long),
540	Int(Int),
541	Short(Short),
542	Byte(Byte),
543	String(String),
544	NormalizedString(NormalizedString),
545	Token(TokenBuf),
546	Language(LanguageBuf),
547	Name(NameBuf),
548	NCName(NCNameBuf),
549	Id(IdBuf),
550	IdRef(IdRefBuf),
551	NMToken(NMTokenBuf),
552	Duration(Duration),
553	DayTimeDuration(DayTimeDuration),
554	YearMonthDuration(YearMonthDuration),
555	DateTime(DateTime),
556	DateTimeStamp(DateTimeStamp),
557	Time(Time),
558	Date(Date),
559	GYearMonth(GYearMonth),
560	GYear(GYear),
561	GMonthDay(GMonthDay),
562	GDay(GDay),
563	GMonth(GMonth),
564	Base64Binary(Base64BinaryBuf),
565	HexBinary(HexBinaryBuf),
566	AnyUri(AnyUriBuf),
567	QName(QNameBuf),
568}
569impl Value {
570	pub fn datatype(&self) -> Datatype {
571		match self {
572			Self::Boolean(_) => Datatype::Boolean,
573			Self::Float(_) => Datatype::Float,
574			Self::Double(_) => Datatype::Double,
575			Self::Decimal(_) => Datatype::Decimal(DecimalDatatype::Decimal),
576			Self::Integer(_) => {
577				Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Integer))
578			}
579			Self::NonPositiveInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
580				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NonPositiveInteger),
581			)),
582			Self::NegativeInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
583				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NegativeInteger),
584			)),
585			Self::NonNegativeInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
586				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::NonNegativeInteger),
587			)),
588			Self::PositiveInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
589				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::PositiveInteger),
590			)),
591			Self::UnsignedLong(_) => Datatype::Decimal(DecimalDatatype::Integer(
592				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
593					UnsignedLongDatatype::UnsignedLong,
594				)),
595			)),
596			Self::UnsignedInt(_) => Datatype::Decimal(DecimalDatatype::Integer(
597				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
598					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt),
599				)),
600			)),
601			Self::UnsignedShort(_) => Datatype::Decimal(DecimalDatatype::Integer(
602				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
603					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(
604						UnsignedShortDatatype::UnsignedShort,
605					)),
606				)),
607			)),
608			Self::UnsignedByte(_) => Datatype::Decimal(DecimalDatatype::Integer(
609				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
610					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(
611						UnsignedShortDatatype::UnsignedByte,
612					)),
613				)),
614			)),
615			Self::Long(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
616				LongDatatype::Long,
617			))),
618			Self::Int(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
619				LongDatatype::Int(IntDatatype::Int),
620			))),
621			Self::Short(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
622				LongDatatype::Int(IntDatatype::Short(ShortDatatype::Short)),
623			))),
624			Self::Byte(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
625				LongDatatype::Int(IntDatatype::Short(ShortDatatype::Byte)),
626			))),
627			Self::String(_) => Datatype::String(StringDatatype::String),
628			Self::NormalizedString(_) => Datatype::String(StringDatatype::NormalizedString(
629				NormalizedStringDatatype::NormalizedString,
630			)),
631			Self::Token(_) => Datatype::String(StringDatatype::NormalizedString(
632				NormalizedStringDatatype::Token(TokenDatatype::Token),
633			)),
634			Self::Language(_) => Datatype::String(StringDatatype::NormalizedString(
635				NormalizedStringDatatype::Token(TokenDatatype::Language),
636			)),
637			Self::Name(_) => Datatype::String(StringDatatype::NormalizedString(
638				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::Name)),
639			)),
640			Self::NCName(_) => Datatype::String(StringDatatype::NormalizedString(
641				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(
642					NCNameDatatype::NCName,
643				))),
644			)),
645			Self::Id(_) => Datatype::String(StringDatatype::NormalizedString(
646				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(
647					NCNameDatatype::Id,
648				))),
649			)),
650			Self::IdRef(_) => Datatype::String(StringDatatype::NormalizedString(
651				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(
652					NCNameDatatype::IdRef,
653				))),
654			)),
655			Self::NMToken(_) => Datatype::String(StringDatatype::NormalizedString(
656				NormalizedStringDatatype::Token(TokenDatatype::NMToken),
657			)),
658			Self::Duration(_) => Datatype::Duration(DurationDatatype::Duration),
659			Self::DayTimeDuration(_) => Datatype::Duration(DurationDatatype::DayTimeDuration),
660			Self::YearMonthDuration(_) => Datatype::Duration(DurationDatatype::YearMonthDuration),
661			Self::DateTime(_) => Datatype::DateTime(DateTimeDatatype::DateTime),
662			Self::DateTimeStamp(_) => Datatype::DateTime(DateTimeDatatype::DateTimeStamp),
663			Self::Time(_) => Datatype::Time,
664			Self::Date(_) => Datatype::Date,
665			Self::GYearMonth(_) => Datatype::GYearMonth,
666			Self::GYear(_) => Datatype::GYear,
667			Self::GMonthDay(_) => Datatype::GMonthDay,
668			Self::GDay(_) => Datatype::GDay,
669			Self::GMonth(_) => Datatype::GMonth,
670			Self::Base64Binary(_) => Datatype::Base64Binary,
671			Self::HexBinary(_) => Datatype::HexBinary,
672			Self::AnyUri(_) => Datatype::AnyUri,
673			Self::QName(_) => Datatype::QName,
674		}
675	}
676}
677impl XsdValue for Value {
678	fn datatype(&self) -> Datatype {
679		self.datatype()
680	}
681}
682impl fmt::Display for Value {
683	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
684		match self {
685			Self::Boolean(v) => v.fmt(f),
686			Self::Float(v) => v.fmt(f),
687			Self::Double(v) => v.fmt(f),
688			Self::Decimal(v) => v.fmt(f),
689			Self::Integer(v) => v.fmt(f),
690			Self::NonPositiveInteger(v) => v.fmt(f),
691			Self::NegativeInteger(v) => v.fmt(f),
692			Self::NonNegativeInteger(v) => v.fmt(f),
693			Self::PositiveInteger(v) => v.fmt(f),
694			Self::UnsignedLong(v) => v.fmt(f),
695			Self::UnsignedInt(v) => v.fmt(f),
696			Self::UnsignedShort(v) => v.fmt(f),
697			Self::UnsignedByte(v) => v.fmt(f),
698			Self::Long(v) => v.fmt(f),
699			Self::Int(v) => v.fmt(f),
700			Self::Short(v) => v.fmt(f),
701			Self::Byte(v) => v.fmt(f),
702			Self::String(v) => v.fmt(f),
703			Self::NormalizedString(v) => v.fmt(f),
704			Self::Token(v) => v.fmt(f),
705			Self::Language(v) => v.fmt(f),
706			Self::Name(v) => v.fmt(f),
707			Self::NCName(v) => v.fmt(f),
708			Self::Id(v) => v.fmt(f),
709			Self::IdRef(v) => v.fmt(f),
710			Self::NMToken(v) => v.fmt(f),
711			Self::Duration(v) => v.fmt(f),
712			Self::DayTimeDuration(v) => v.fmt(f),
713			Self::YearMonthDuration(v) => v.fmt(f),
714			Self::DateTime(v) => v.fmt(f),
715			Self::DateTimeStamp(v) => v.fmt(f),
716			Self::Time(v) => v.fmt(f),
717			Self::Date(v) => v.fmt(f),
718			Self::GYearMonth(v) => v.fmt(f),
719			Self::GYear(v) => v.fmt(f),
720			Self::GMonthDay(v) => v.fmt(f),
721			Self::GDay(v) => v.fmt(f),
722			Self::GMonth(v) => v.fmt(f),
723			Self::Base64Binary(v) => v.fmt(f),
724			Self::HexBinary(v) => v.fmt(f),
725			Self::AnyUri(v) => v.fmt(f),
726			Self::QName(v) => v.fmt(f),
727		}
728	}
729}
730/// Any XSD value reference.
731#[derive(Debug, Clone, Copy)]
732pub enum ValueRef<'a> {
733	Boolean(Boolean),
734	Float(Float),
735	Double(Double),
736	Decimal(&'a Decimal),
737	Integer(&'a Integer),
738	NonPositiveInteger(&'a NonPositiveInteger),
739	NegativeInteger(&'a NegativeInteger),
740	NonNegativeInteger(&'a NonNegativeInteger),
741	PositiveInteger(&'a PositiveInteger),
742	UnsignedLong(UnsignedLong),
743	UnsignedInt(UnsignedInt),
744	UnsignedShort(UnsignedShort),
745	UnsignedByte(UnsignedByte),
746	Long(Long),
747	Int(Int),
748	Short(Short),
749	Byte(Byte),
750	String(&'a str),
751	NormalizedString(&'a NormalizedStr),
752	Token(&'a Token),
753	Language(&'a Language),
754	Name(&'a Name),
755	NCName(&'a NCName),
756	Id(&'a Id),
757	IdRef(&'a IdRef),
758	NMToken(&'a NMToken),
759	Duration(Duration),
760	DayTimeDuration(DayTimeDuration),
761	YearMonthDuration(YearMonthDuration),
762	DateTime(DateTime),
763	DateTimeStamp(DateTimeStamp),
764	Time(Time),
765	Date(Date),
766	GYearMonth(GYearMonth),
767	GYear(GYear),
768	GMonthDay(GMonthDay),
769	GDay(GDay),
770	GMonth(GMonth),
771	Base64Binary(&'a Base64Binary),
772	HexBinary(&'a HexBinary),
773	AnyUri(&'a AnyUri),
774	QName(&'a QName),
775}
776impl<'a> fmt::Display for ValueRef<'a> {
777	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
778		match self {
779			Self::Boolean(v) => v.fmt(f),
780			Self::Float(v) => v.fmt(f),
781			Self::Double(v) => v.fmt(f),
782			Self::Decimal(v) => v.fmt(f),
783			Self::Integer(v) => v.fmt(f),
784			Self::NonPositiveInteger(v) => v.fmt(f),
785			Self::NegativeInteger(v) => v.fmt(f),
786			Self::NonNegativeInteger(v) => v.fmt(f),
787			Self::PositiveInteger(v) => v.fmt(f),
788			Self::UnsignedLong(v) => v.fmt(f),
789			Self::UnsignedInt(v) => v.fmt(f),
790			Self::UnsignedShort(v) => v.fmt(f),
791			Self::UnsignedByte(v) => v.fmt(f),
792			Self::Long(v) => v.fmt(f),
793			Self::Int(v) => v.fmt(f),
794			Self::Short(v) => v.fmt(f),
795			Self::Byte(v) => v.fmt(f),
796			Self::String(v) => v.fmt(f),
797			Self::NormalizedString(v) => v.fmt(f),
798			Self::Token(v) => v.fmt(f),
799			Self::Language(v) => v.fmt(f),
800			Self::Name(v) => v.fmt(f),
801			Self::NCName(v) => v.fmt(f),
802			Self::Id(v) => v.fmt(f),
803			Self::IdRef(v) => v.fmt(f),
804			Self::NMToken(v) => v.fmt(f),
805			Self::Duration(v) => v.fmt(f),
806			Self::DayTimeDuration(v) => v.fmt(f),
807			Self::YearMonthDuration(v) => v.fmt(f),
808			Self::DateTime(v) => v.fmt(f),
809			Self::DateTimeStamp(v) => v.fmt(f),
810			Self::Time(v) => v.fmt(f),
811			Self::Date(v) => v.fmt(f),
812			Self::GYearMonth(v) => v.fmt(f),
813			Self::GYear(v) => v.fmt(f),
814			Self::GMonthDay(v) => v.fmt(f),
815			Self::GDay(v) => v.fmt(f),
816			Self::GMonth(v) => v.fmt(f),
817			Self::Base64Binary(v) => v.fmt(f),
818			Self::HexBinary(v) => v.fmt(f),
819			Self::AnyUri(v) => v.fmt(f),
820			Self::QName(v) => v.fmt(f),
821		}
822	}
823}
824impl Value {
825	pub fn as_ref(&self) -> ValueRef {
826		match self {
827			Self::Boolean(value) => ValueRef::Boolean(*value),
828			Self::Float(value) => ValueRef::Float(*value),
829			Self::Double(value) => ValueRef::Double(*value),
830			Self::Decimal(value) => ValueRef::Decimal(value),
831			Self::Integer(value) => ValueRef::Integer(value),
832			Self::NonPositiveInteger(value) => ValueRef::NonPositiveInteger(value),
833			Self::NegativeInteger(value) => ValueRef::NegativeInteger(value),
834			Self::NonNegativeInteger(value) => ValueRef::NonNegativeInteger(value),
835			Self::PositiveInteger(value) => ValueRef::PositiveInteger(value),
836			Self::UnsignedLong(value) => ValueRef::UnsignedLong(*value),
837			Self::UnsignedInt(value) => ValueRef::UnsignedInt(*value),
838			Self::UnsignedShort(value) => ValueRef::UnsignedShort(*value),
839			Self::UnsignedByte(value) => ValueRef::UnsignedByte(*value),
840			Self::Long(value) => ValueRef::Long(*value),
841			Self::Int(value) => ValueRef::Int(*value),
842			Self::Short(value) => ValueRef::Short(*value),
843			Self::Byte(value) => ValueRef::Byte(*value),
844			Self::String(value) => ValueRef::String(value),
845			Self::NormalizedString(value) => ValueRef::NormalizedString(value),
846			Self::Token(value) => ValueRef::Token(value),
847			Self::Language(value) => ValueRef::Language(value),
848			Self::Name(value) => ValueRef::Name(value),
849			Self::NCName(value) => ValueRef::NCName(value),
850			Self::Id(value) => ValueRef::Id(value),
851			Self::IdRef(value) => ValueRef::IdRef(value),
852			Self::NMToken(value) => ValueRef::NMToken(value),
853			Self::Duration(value) => ValueRef::Duration(*value),
854			Self::DayTimeDuration(value) => ValueRef::DayTimeDuration(*value),
855			Self::YearMonthDuration(value) => ValueRef::YearMonthDuration(*value),
856			Self::DateTime(value) => ValueRef::DateTime(*value),
857			Self::DateTimeStamp(value) => ValueRef::DateTimeStamp(*value),
858			Self::Time(value) => ValueRef::Time(*value),
859			Self::Date(value) => ValueRef::Date(*value),
860			Self::GYearMonth(value) => ValueRef::GYearMonth(*value),
861			Self::GYear(value) => ValueRef::GYear(*value),
862			Self::GMonthDay(value) => ValueRef::GMonthDay(*value),
863			Self::GDay(value) => ValueRef::GDay(*value),
864			Self::GMonth(value) => ValueRef::GMonth(*value),
865			Self::Base64Binary(value) => ValueRef::Base64Binary(value),
866			Self::HexBinary(value) => ValueRef::HexBinary(value),
867			Self::AnyUri(value) => ValueRef::AnyUri(value),
868			Self::QName(value) => ValueRef::QName(value),
869		}
870	}
871}
872impl<'a> ValueRef<'a> {
873	pub fn datatype(&self) -> Datatype {
874		match self {
875			Self::Boolean(_) => Datatype::Boolean,
876			Self::Float(_) => Datatype::Float,
877			Self::Double(_) => Datatype::Double,
878			Self::Decimal(_) => Datatype::Decimal(DecimalDatatype::Decimal),
879			Self::Integer(_) => {
880				Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Integer))
881			}
882			Self::NonPositiveInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
883				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NonPositiveInteger),
884			)),
885			Self::NegativeInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
886				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NegativeInteger),
887			)),
888			Self::NonNegativeInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
889				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::NonNegativeInteger),
890			)),
891			Self::PositiveInteger(_) => Datatype::Decimal(DecimalDatatype::Integer(
892				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::PositiveInteger),
893			)),
894			Self::UnsignedLong(_) => Datatype::Decimal(DecimalDatatype::Integer(
895				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
896					UnsignedLongDatatype::UnsignedLong,
897				)),
898			)),
899			Self::UnsignedInt(_) => Datatype::Decimal(DecimalDatatype::Integer(
900				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
901					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt),
902				)),
903			)),
904			Self::UnsignedShort(_) => Datatype::Decimal(DecimalDatatype::Integer(
905				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
906					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(
907						UnsignedShortDatatype::UnsignedShort,
908					)),
909				)),
910			)),
911			Self::UnsignedByte(_) => Datatype::Decimal(DecimalDatatype::Integer(
912				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
913					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(
914						UnsignedShortDatatype::UnsignedByte,
915					)),
916				)),
917			)),
918			Self::Long(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
919				LongDatatype::Long,
920			))),
921			Self::Int(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
922				LongDatatype::Int(IntDatatype::Int),
923			))),
924			Self::Short(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
925				LongDatatype::Int(IntDatatype::Short(ShortDatatype::Short)),
926			))),
927			Self::Byte(_) => Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
928				LongDatatype::Int(IntDatatype::Short(ShortDatatype::Byte)),
929			))),
930			Self::String(_) => Datatype::String(StringDatatype::String),
931			Self::NormalizedString(_) => Datatype::String(StringDatatype::NormalizedString(
932				NormalizedStringDatatype::NormalizedString,
933			)),
934			Self::Token(_) => Datatype::String(StringDatatype::NormalizedString(
935				NormalizedStringDatatype::Token(TokenDatatype::Token),
936			)),
937			Self::Language(_) => Datatype::String(StringDatatype::NormalizedString(
938				NormalizedStringDatatype::Token(TokenDatatype::Language),
939			)),
940			Self::Name(_) => Datatype::String(StringDatatype::NormalizedString(
941				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::Name)),
942			)),
943			Self::NCName(_) => Datatype::String(StringDatatype::NormalizedString(
944				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(
945					NCNameDatatype::NCName,
946				))),
947			)),
948			Self::Id(_) => Datatype::String(StringDatatype::NormalizedString(
949				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(
950					NCNameDatatype::Id,
951				))),
952			)),
953			Self::IdRef(_) => Datatype::String(StringDatatype::NormalizedString(
954				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(
955					NCNameDatatype::IdRef,
956				))),
957			)),
958			Self::NMToken(_) => Datatype::String(StringDatatype::NormalizedString(
959				NormalizedStringDatatype::Token(TokenDatatype::NMToken),
960			)),
961			Self::Duration(_) => Datatype::Duration(DurationDatatype::Duration),
962			Self::DayTimeDuration(_) => Datatype::Duration(DurationDatatype::DayTimeDuration),
963			Self::YearMonthDuration(_) => Datatype::Duration(DurationDatatype::YearMonthDuration),
964			Self::DateTime(_) => Datatype::DateTime(DateTimeDatatype::DateTime),
965			Self::DateTimeStamp(_) => Datatype::DateTime(DateTimeDatatype::DateTimeStamp),
966			Self::Time(_) => Datatype::Time,
967			Self::Date(_) => Datatype::Date,
968			Self::GYearMonth(_) => Datatype::GYearMonth,
969			Self::GYear(_) => Datatype::GYear,
970			Self::GMonthDay(_) => Datatype::GMonthDay,
971			Self::GDay(_) => Datatype::GDay,
972			Self::GMonth(_) => Datatype::GMonth,
973			Self::Base64Binary(_) => Datatype::Base64Binary,
974			Self::HexBinary(_) => Datatype::HexBinary,
975			Self::AnyUri(_) => Datatype::AnyUri,
976			Self::QName(_) => Datatype::QName,
977		}
978	}
979	pub fn into_owned(self) -> Value {
980		match self {
981			Self::Boolean(value) => Value::Boolean(value),
982			Self::Float(value) => Value::Float(value),
983			Self::Double(value) => Value::Double(value),
984			Self::Decimal(value) => Value::Decimal(value.to_owned()),
985			Self::Integer(value) => Value::Integer(value.to_owned()),
986			Self::NonPositiveInteger(value) => Value::NonPositiveInteger(value.to_owned()),
987			Self::NegativeInteger(value) => Value::NegativeInteger(value.to_owned()),
988			Self::NonNegativeInteger(value) => Value::NonNegativeInteger(value.to_owned()),
989			Self::PositiveInteger(value) => Value::PositiveInteger(value.to_owned()),
990			Self::UnsignedLong(value) => Value::UnsignedLong(value),
991			Self::UnsignedInt(value) => Value::UnsignedInt(value),
992			Self::UnsignedShort(value) => Value::UnsignedShort(value),
993			Self::UnsignedByte(value) => Value::UnsignedByte(value),
994			Self::Long(value) => Value::Long(value),
995			Self::Int(value) => Value::Int(value),
996			Self::Short(value) => Value::Short(value),
997			Self::Byte(value) => Value::Byte(value),
998			Self::String(value) => Value::String(value.to_owned()),
999			Self::NormalizedString(value) => Value::NormalizedString(value.to_owned()),
1000			Self::Token(value) => Value::Token(value.to_owned()),
1001			Self::Language(value) => Value::Language(value.to_owned()),
1002			Self::Name(value) => Value::Name(value.to_owned()),
1003			Self::NCName(value) => Value::NCName(value.to_owned()),
1004			Self::Id(value) => Value::Id(value.to_owned()),
1005			Self::IdRef(value) => Value::IdRef(value.to_owned()),
1006			Self::NMToken(value) => Value::NMToken(value.to_owned()),
1007			Self::Duration(value) => Value::Duration(value),
1008			Self::DayTimeDuration(value) => Value::DayTimeDuration(value),
1009			Self::YearMonthDuration(value) => Value::YearMonthDuration(value),
1010			Self::DateTime(value) => Value::DateTime(value),
1011			Self::DateTimeStamp(value) => Value::DateTimeStamp(value),
1012			Self::Time(value) => Value::Time(value),
1013			Self::Date(value) => Value::Date(value),
1014			Self::GYearMonth(value) => Value::GYearMonth(value),
1015			Self::GYear(value) => Value::GYear(value),
1016			Self::GMonthDay(value) => Value::GMonthDay(value),
1017			Self::GDay(value) => Value::GDay(value),
1018			Self::GMonth(value) => Value::GMonth(value),
1019			Self::Base64Binary(value) => Value::Base64Binary(value.to_owned()),
1020			Self::HexBinary(value) => Value::HexBinary(value.to_owned()),
1021			Self::AnyUri(value) => Value::AnyUri(value.to_owned()),
1022			Self::QName(value) => Value::QName(value.to_owned()),
1023		}
1024	}
1025	pub fn cloned(&self) -> Value {
1026		self.into_owned()
1027	}
1028}
1029impl<'a> XsdValue for ValueRef<'a> {
1030	fn datatype(&self) -> Datatype {
1031		self.datatype()
1032	}
1033}
1034impl From<DecimalDatatype> for Datatype {
1035	fn from(value: DecimalDatatype) -> Self {
1036		Self::Decimal(value)
1037	}
1038}
1039impl From<IntegerDatatype> for Datatype {
1040	fn from(value: IntegerDatatype) -> Self {
1041		Self::Decimal(DecimalDatatype::Integer(value))
1042	}
1043}
1044impl From<NonPositiveIntegerDatatype> for Datatype {
1045	fn from(value: NonPositiveIntegerDatatype) -> Self {
1046		Self::Decimal(DecimalDatatype::Integer(
1047			IntegerDatatype::NonPositiveInteger(value),
1048		))
1049	}
1050}
1051impl From<NonNegativeIntegerDatatype> for Datatype {
1052	fn from(value: NonNegativeIntegerDatatype) -> Self {
1053		Self::Decimal(DecimalDatatype::Integer(
1054			IntegerDatatype::NonNegativeInteger(value),
1055		))
1056	}
1057}
1058impl From<UnsignedLongDatatype> for Datatype {
1059	fn from(value: UnsignedLongDatatype) -> Self {
1060		Self::Decimal(DecimalDatatype::Integer(
1061			IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(value)),
1062		))
1063	}
1064}
1065impl From<UnsignedIntDatatype> for Datatype {
1066	fn from(value: UnsignedIntDatatype) -> Self {
1067		Self::Decimal(DecimalDatatype::Integer(
1068			IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1069				UnsignedLongDatatype::UnsignedInt(value),
1070			)),
1071		))
1072	}
1073}
1074impl From<UnsignedShortDatatype> for Datatype {
1075	fn from(value: UnsignedShortDatatype) -> Self {
1076		Self::Decimal(DecimalDatatype::Integer(
1077			IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1078				UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(value)),
1079			)),
1080		))
1081	}
1082}
1083impl From<LongDatatype> for Datatype {
1084	fn from(value: LongDatatype) -> Self {
1085		Self::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(value)))
1086	}
1087}
1088impl From<IntDatatype> for Datatype {
1089	fn from(value: IntDatatype) -> Self {
1090		Self::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
1091			LongDatatype::Int(value),
1092		)))
1093	}
1094}
1095impl From<ShortDatatype> for Datatype {
1096	fn from(value: ShortDatatype) -> Self {
1097		Self::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
1098			LongDatatype::Int(IntDatatype::Short(value)),
1099		)))
1100	}
1101}
1102impl TryFrom<Datatype> for DecimalDatatype {
1103	type Error = Datatype;
1104	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1105		match value {
1106			Datatype::Decimal(value) => Ok(value),
1107			other => Err(other),
1108		}
1109	}
1110}
1111impl TryFrom<Datatype> for IntegerDatatype {
1112	type Error = Datatype;
1113	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1114		match value {
1115			Datatype::Decimal(DecimalDatatype::Integer(value)) => Ok(value),
1116			other => Err(other),
1117		}
1118	}
1119}
1120impl TryFrom<Datatype> for NonPositiveIntegerDatatype {
1121	type Error = Datatype;
1122	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1123		match value {
1124			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::NonPositiveInteger(
1125				value,
1126			))) => Ok(value),
1127			other => Err(other),
1128		}
1129	}
1130}
1131impl TryFrom<Datatype> for NonNegativeIntegerDatatype {
1132	type Error = Datatype;
1133	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1134		match value {
1135			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1136				value,
1137			))) => Ok(value),
1138			other => Err(other),
1139		}
1140	}
1141}
1142impl TryFrom<Datatype> for UnsignedLongDatatype {
1143	type Error = Datatype;
1144	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1145		match value {
1146			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1147				NonNegativeIntegerDatatype::UnsignedLong(value),
1148			))) => Ok(value),
1149			other => Err(other),
1150		}
1151	}
1152}
1153impl TryFrom<Datatype> for UnsignedIntDatatype {
1154	type Error = Datatype;
1155	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1156		match value {
1157			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1158				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(value)),
1159			))) => Ok(value),
1160			other => Err(other),
1161		}
1162	}
1163}
1164impl TryFrom<Datatype> for UnsignedShortDatatype {
1165	type Error = Datatype;
1166	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1167		match value {
1168			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1169				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
1170					UnsignedIntDatatype::UnsignedShort(value),
1171				)),
1172			))) => Ok(value),
1173			other => Err(other),
1174		}
1175	}
1176}
1177impl TryFrom<Datatype> for LongDatatype {
1178	type Error = Datatype;
1179	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1180		match value {
1181			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(value))) => Ok(value),
1182			other => Err(other),
1183		}
1184	}
1185}
1186impl TryFrom<Datatype> for IntDatatype {
1187	type Error = Datatype;
1188	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1189		match value {
1190			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
1191				LongDatatype::Int(value),
1192			))) => Ok(value),
1193			other => Err(other),
1194		}
1195	}
1196}
1197impl TryFrom<Datatype> for ShortDatatype {
1198	type Error = Datatype;
1199	fn try_from(value: Datatype) -> Result<Self, Datatype> {
1200		match value {
1201			Datatype::Decimal(DecimalDatatype::Integer(IntegerDatatype::Long(
1202				LongDatatype::Int(IntDatatype::Short(value)),
1203			))) => Ok(value),
1204			other => Err(other),
1205		}
1206	}
1207}
1208impl From<DecimalValue> for Value {
1209	fn from(value: DecimalValue) -> Self {
1210		match value {
1211			DecimalValue::Decimal(value) => Self::Decimal(value),
1212			DecimalValue::Integer(value) => Self::Integer(value),
1213			DecimalValue::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1214			DecimalValue::NegativeInteger(value) => Self::NegativeInteger(value),
1215			DecimalValue::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1216			DecimalValue::PositiveInteger(value) => Self::PositiveInteger(value),
1217			DecimalValue::UnsignedLong(value) => Self::UnsignedLong(value),
1218			DecimalValue::UnsignedInt(value) => Self::UnsignedInt(value),
1219			DecimalValue::UnsignedShort(value) => Self::UnsignedShort(value),
1220			DecimalValue::UnsignedByte(value) => Self::UnsignedByte(value),
1221			DecimalValue::Long(value) => Self::Long(value),
1222			DecimalValue::Int(value) => Self::Int(value),
1223			DecimalValue::Short(value) => Self::Short(value),
1224			DecimalValue::Byte(value) => Self::Byte(value),
1225		}
1226	}
1227}
1228impl From<IntegerValue> for Value {
1229	fn from(value: IntegerValue) -> Self {
1230		match value {
1231			IntegerValue::Integer(value) => Self::Integer(value),
1232			IntegerValue::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1233			IntegerValue::NegativeInteger(value) => Self::NegativeInteger(value),
1234			IntegerValue::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1235			IntegerValue::PositiveInteger(value) => Self::PositiveInteger(value),
1236			IntegerValue::UnsignedLong(value) => Self::UnsignedLong(value),
1237			IntegerValue::UnsignedInt(value) => Self::UnsignedInt(value),
1238			IntegerValue::UnsignedShort(value) => Self::UnsignedShort(value),
1239			IntegerValue::UnsignedByte(value) => Self::UnsignedByte(value),
1240			IntegerValue::Long(value) => Self::Long(value),
1241			IntegerValue::Int(value) => Self::Int(value),
1242			IntegerValue::Short(value) => Self::Short(value),
1243			IntegerValue::Byte(value) => Self::Byte(value),
1244		}
1245	}
1246}
1247impl From<NonPositiveIntegerValue> for Value {
1248	fn from(value: NonPositiveIntegerValue) -> Self {
1249		match value {
1250			NonPositiveIntegerValue::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1251			NonPositiveIntegerValue::NegativeInteger(value) => Self::NegativeInteger(value),
1252		}
1253	}
1254}
1255impl From<NonNegativeIntegerValue> for Value {
1256	fn from(value: NonNegativeIntegerValue) -> Self {
1257		match value {
1258			NonNegativeIntegerValue::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1259			NonNegativeIntegerValue::PositiveInteger(value) => Self::PositiveInteger(value),
1260			NonNegativeIntegerValue::UnsignedLong(value) => Self::UnsignedLong(value),
1261			NonNegativeIntegerValue::UnsignedInt(value) => Self::UnsignedInt(value),
1262			NonNegativeIntegerValue::UnsignedShort(value) => Self::UnsignedShort(value),
1263			NonNegativeIntegerValue::UnsignedByte(value) => Self::UnsignedByte(value),
1264		}
1265	}
1266}
1267impl From<UnsignedLongValue> for Value {
1268	fn from(value: UnsignedLongValue) -> Self {
1269		match value {
1270			UnsignedLongValue::UnsignedLong(value) => Self::UnsignedLong(value),
1271			UnsignedLongValue::UnsignedInt(value) => Self::UnsignedInt(value),
1272			UnsignedLongValue::UnsignedShort(value) => Self::UnsignedShort(value),
1273			UnsignedLongValue::UnsignedByte(value) => Self::UnsignedByte(value),
1274		}
1275	}
1276}
1277impl From<UnsignedIntValue> for Value {
1278	fn from(value: UnsignedIntValue) -> Self {
1279		match value {
1280			UnsignedIntValue::UnsignedInt(value) => Self::UnsignedInt(value),
1281			UnsignedIntValue::UnsignedShort(value) => Self::UnsignedShort(value),
1282			UnsignedIntValue::UnsignedByte(value) => Self::UnsignedByte(value),
1283		}
1284	}
1285}
1286impl From<UnsignedShortValue> for Value {
1287	fn from(value: UnsignedShortValue) -> Self {
1288		match value {
1289			UnsignedShortValue::UnsignedShort(value) => Self::UnsignedShort(value),
1290			UnsignedShortValue::UnsignedByte(value) => Self::UnsignedByte(value),
1291		}
1292	}
1293}
1294impl From<LongValue> for Value {
1295	fn from(value: LongValue) -> Self {
1296		match value {
1297			LongValue::Long(value) => Self::Long(value),
1298			LongValue::Int(value) => Self::Int(value),
1299			LongValue::Short(value) => Self::Short(value),
1300			LongValue::Byte(value) => Self::Byte(value),
1301		}
1302	}
1303}
1304impl From<IntValue> for Value {
1305	fn from(value: IntValue) -> Self {
1306		match value {
1307			IntValue::Int(value) => Self::Int(value),
1308			IntValue::Short(value) => Self::Short(value),
1309			IntValue::Byte(value) => Self::Byte(value),
1310		}
1311	}
1312}
1313impl From<ShortValue> for Value {
1314	fn from(value: ShortValue) -> Self {
1315		match value {
1316			ShortValue::Short(value) => Self::Short(value),
1317			ShortValue::Byte(value) => Self::Byte(value),
1318		}
1319	}
1320}
1321impl TryFrom<Value> for DecimalValue {
1322	type Error = Value;
1323	fn try_from(value: Value) -> Result<Self, Value> {
1324		match value {
1325			Value::Decimal(value) => Ok(Self::Decimal(value)),
1326			Value::Integer(value) => Ok(Self::Integer(value)),
1327			Value::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1328			Value::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1329			Value::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1330			Value::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1331			Value::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1332			Value::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1333			Value::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1334			Value::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1335			Value::Long(value) => Ok(Self::Long(value)),
1336			Value::Int(value) => Ok(Self::Int(value)),
1337			Value::Short(value) => Ok(Self::Short(value)),
1338			Value::Byte(value) => Ok(Self::Byte(value)),
1339			other => Err(other),
1340		}
1341	}
1342}
1343impl TryFrom<Value> for IntegerValue {
1344	type Error = Value;
1345	fn try_from(value: Value) -> Result<Self, Value> {
1346		match value {
1347			Value::Integer(value) => Ok(Self::Integer(value)),
1348			Value::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1349			Value::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1350			Value::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1351			Value::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1352			Value::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1353			Value::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1354			Value::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1355			Value::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1356			Value::Long(value) => Ok(Self::Long(value)),
1357			Value::Int(value) => Ok(Self::Int(value)),
1358			Value::Short(value) => Ok(Self::Short(value)),
1359			Value::Byte(value) => Ok(Self::Byte(value)),
1360			other => Err(other),
1361		}
1362	}
1363}
1364impl TryFrom<Value> for NonPositiveIntegerValue {
1365	type Error = Value;
1366	fn try_from(value: Value) -> Result<Self, Value> {
1367		match value {
1368			Value::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1369			Value::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1370			other => Err(other),
1371		}
1372	}
1373}
1374impl TryFrom<Value> for NonNegativeIntegerValue {
1375	type Error = Value;
1376	fn try_from(value: Value) -> Result<Self, Value> {
1377		match value {
1378			Value::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1379			Value::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1380			Value::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1381			Value::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1382			Value::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1383			Value::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1384			other => Err(other),
1385		}
1386	}
1387}
1388impl TryFrom<Value> for UnsignedLongValue {
1389	type Error = Value;
1390	fn try_from(value: Value) -> Result<Self, Value> {
1391		match value {
1392			Value::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1393			Value::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1394			Value::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1395			Value::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1396			other => Err(other),
1397		}
1398	}
1399}
1400impl TryFrom<Value> for UnsignedIntValue {
1401	type Error = Value;
1402	fn try_from(value: Value) -> Result<Self, Value> {
1403		match value {
1404			Value::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1405			Value::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1406			Value::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1407			other => Err(other),
1408		}
1409	}
1410}
1411impl TryFrom<Value> for UnsignedShortValue {
1412	type Error = Value;
1413	fn try_from(value: Value) -> Result<Self, Value> {
1414		match value {
1415			Value::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1416			Value::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1417			other => Err(other),
1418		}
1419	}
1420}
1421impl TryFrom<Value> for LongValue {
1422	type Error = Value;
1423	fn try_from(value: Value) -> Result<Self, Value> {
1424		match value {
1425			Value::Long(value) => Ok(Self::Long(value)),
1426			Value::Int(value) => Ok(Self::Int(value)),
1427			Value::Short(value) => Ok(Self::Short(value)),
1428			Value::Byte(value) => Ok(Self::Byte(value)),
1429			other => Err(other),
1430		}
1431	}
1432}
1433impl TryFrom<Value> for IntValue {
1434	type Error = Value;
1435	fn try_from(value: Value) -> Result<Self, Value> {
1436		match value {
1437			Value::Int(value) => Ok(Self::Int(value)),
1438			Value::Short(value) => Ok(Self::Short(value)),
1439			Value::Byte(value) => Ok(Self::Byte(value)),
1440			other => Err(other),
1441		}
1442	}
1443}
1444impl TryFrom<Value> for ShortValue {
1445	type Error = Value;
1446	fn try_from(value: Value) -> Result<Self, Value> {
1447		match value {
1448			Value::Short(value) => Ok(Self::Short(value)),
1449			Value::Byte(value) => Ok(Self::Byte(value)),
1450			other => Err(other),
1451		}
1452	}
1453}
1454impl<'a> From<DecimalValueRef<'a>> for ValueRef<'a> {
1455	fn from(value: DecimalValueRef<'a>) -> Self {
1456		match value {
1457			DecimalValueRef::Decimal(value) => Self::Decimal(value),
1458			DecimalValueRef::Integer(value) => Self::Integer(value),
1459			DecimalValueRef::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1460			DecimalValueRef::NegativeInteger(value) => Self::NegativeInteger(value),
1461			DecimalValueRef::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1462			DecimalValueRef::PositiveInteger(value) => Self::PositiveInteger(value),
1463			DecimalValueRef::UnsignedLong(value) => Self::UnsignedLong(value),
1464			DecimalValueRef::UnsignedInt(value) => Self::UnsignedInt(value),
1465			DecimalValueRef::UnsignedShort(value) => Self::UnsignedShort(value),
1466			DecimalValueRef::UnsignedByte(value) => Self::UnsignedByte(value),
1467			DecimalValueRef::Long(value) => Self::Long(value),
1468			DecimalValueRef::Int(value) => Self::Int(value),
1469			DecimalValueRef::Short(value) => Self::Short(value),
1470			DecimalValueRef::Byte(value) => Self::Byte(value),
1471		}
1472	}
1473}
1474impl<'a> From<IntegerValueRef<'a>> for ValueRef<'a> {
1475	fn from(value: IntegerValueRef<'a>) -> Self {
1476		match value {
1477			IntegerValueRef::Integer(value) => Self::Integer(value),
1478			IntegerValueRef::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1479			IntegerValueRef::NegativeInteger(value) => Self::NegativeInteger(value),
1480			IntegerValueRef::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1481			IntegerValueRef::PositiveInteger(value) => Self::PositiveInteger(value),
1482			IntegerValueRef::UnsignedLong(value) => Self::UnsignedLong(value),
1483			IntegerValueRef::UnsignedInt(value) => Self::UnsignedInt(value),
1484			IntegerValueRef::UnsignedShort(value) => Self::UnsignedShort(value),
1485			IntegerValueRef::UnsignedByte(value) => Self::UnsignedByte(value),
1486			IntegerValueRef::Long(value) => Self::Long(value),
1487			IntegerValueRef::Int(value) => Self::Int(value),
1488			IntegerValueRef::Short(value) => Self::Short(value),
1489			IntegerValueRef::Byte(value) => Self::Byte(value),
1490		}
1491	}
1492}
1493impl<'a> From<NonPositiveIntegerValueRef<'a>> for ValueRef<'a> {
1494	fn from(value: NonPositiveIntegerValueRef<'a>) -> Self {
1495		match value {
1496			NonPositiveIntegerValueRef::NonPositiveInteger(value) => {
1497				Self::NonPositiveInteger(value)
1498			}
1499			NonPositiveIntegerValueRef::NegativeInteger(value) => Self::NegativeInteger(value),
1500		}
1501	}
1502}
1503impl<'a> From<NonNegativeIntegerValueRef<'a>> for ValueRef<'a> {
1504	fn from(value: NonNegativeIntegerValueRef<'a>) -> Self {
1505		match value {
1506			NonNegativeIntegerValueRef::NonNegativeInteger(value) => {
1507				Self::NonNegativeInteger(value)
1508			}
1509			NonNegativeIntegerValueRef::PositiveInteger(value) => Self::PositiveInteger(value),
1510			NonNegativeIntegerValueRef::UnsignedLong(value) => Self::UnsignedLong(value),
1511			NonNegativeIntegerValueRef::UnsignedInt(value) => Self::UnsignedInt(value),
1512			NonNegativeIntegerValueRef::UnsignedShort(value) => Self::UnsignedShort(value),
1513			NonNegativeIntegerValueRef::UnsignedByte(value) => Self::UnsignedByte(value),
1514		}
1515	}
1516}
1517impl<'a> TryFrom<ValueRef<'a>> for DecimalValueRef<'a> {
1518	type Error = ValueRef<'a>;
1519	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
1520		match value {
1521			ValueRef::Decimal(value) => Ok(Self::Decimal(value)),
1522			ValueRef::Integer(value) => Ok(Self::Integer(value)),
1523			ValueRef::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1524			ValueRef::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1525			ValueRef::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1526			ValueRef::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1527			ValueRef::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1528			ValueRef::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1529			ValueRef::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1530			ValueRef::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1531			ValueRef::Long(value) => Ok(Self::Long(value)),
1532			ValueRef::Int(value) => Ok(Self::Int(value)),
1533			ValueRef::Short(value) => Ok(Self::Short(value)),
1534			ValueRef::Byte(value) => Ok(Self::Byte(value)),
1535			other => Err(other),
1536		}
1537	}
1538}
1539impl<'a> TryFrom<ValueRef<'a>> for IntegerValueRef<'a> {
1540	type Error = ValueRef<'a>;
1541	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
1542		match value {
1543			ValueRef::Integer(value) => Ok(Self::Integer(value)),
1544			ValueRef::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1545			ValueRef::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1546			ValueRef::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1547			ValueRef::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1548			ValueRef::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1549			ValueRef::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1550			ValueRef::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1551			ValueRef::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1552			ValueRef::Long(value) => Ok(Self::Long(value)),
1553			ValueRef::Int(value) => Ok(Self::Int(value)),
1554			ValueRef::Short(value) => Ok(Self::Short(value)),
1555			ValueRef::Byte(value) => Ok(Self::Byte(value)),
1556			other => Err(other),
1557		}
1558	}
1559}
1560impl<'a> TryFrom<ValueRef<'a>> for NonPositiveIntegerValueRef<'a> {
1561	type Error = ValueRef<'a>;
1562	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
1563		match value {
1564			ValueRef::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1565			ValueRef::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1566			other => Err(other),
1567		}
1568	}
1569}
1570impl<'a> TryFrom<ValueRef<'a>> for NonNegativeIntegerValueRef<'a> {
1571	type Error = ValueRef<'a>;
1572	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
1573		match value {
1574			ValueRef::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1575			ValueRef::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1576			ValueRef::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1577			ValueRef::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1578			ValueRef::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1579			ValueRef::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1580			other => Err(other),
1581		}
1582	}
1583}
1584/// Any specialized [`Decimal`] value.
1585#[derive(Debug, Clone)]
1586pub enum DecimalValue {
1587	Decimal(Decimal),
1588	Integer(Integer),
1589	NonPositiveInteger(NonPositiveInteger),
1590	NegativeInteger(NegativeInteger),
1591	NonNegativeInteger(NonNegativeInteger),
1592	PositiveInteger(PositiveInteger),
1593	UnsignedLong(UnsignedLong),
1594	UnsignedInt(UnsignedInt),
1595	UnsignedShort(UnsignedShort),
1596	UnsignedByte(UnsignedByte),
1597	Long(Long),
1598	Int(Int),
1599	Short(Short),
1600	Byte(Byte),
1601}
1602impl DecimalValue {
1603	pub fn datatype(&self) -> DecimalDatatype {
1604		match self {
1605			Self::Decimal(_) => DecimalDatatype::Decimal,
1606			Self::Integer(_) => DecimalDatatype::Integer(IntegerDatatype::Integer),
1607			Self::NonPositiveInteger(_) => DecimalDatatype::Integer(
1608				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NonPositiveInteger),
1609			),
1610			Self::NegativeInteger(_) => DecimalDatatype::Integer(
1611				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NegativeInteger),
1612			),
1613			Self::NonNegativeInteger(_) => DecimalDatatype::Integer(
1614				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::NonNegativeInteger),
1615			),
1616			Self::PositiveInteger(_) => DecimalDatatype::Integer(
1617				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::PositiveInteger),
1618			),
1619			Self::UnsignedLong(_) => DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1620				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedLong),
1621			)),
1622			Self::UnsignedInt(_) => DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1623				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
1624					UnsignedIntDatatype::UnsignedInt,
1625				)),
1626			)),
1627			Self::UnsignedShort(_) => {
1628				DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1629					NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
1630						UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
1631					)),
1632				))
1633			}
1634			Self::UnsignedByte(_) => DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
1635				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
1636					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
1637				)),
1638			)),
1639			Self::Long(_) => DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Long)),
1640			Self::Int(_) => {
1641				DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Int)))
1642			}
1643			Self::Short(_) => DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(
1644				IntDatatype::Short(ShortDatatype::Short),
1645			))),
1646			Self::Byte(_) => DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(
1647				IntDatatype::Short(ShortDatatype::Byte),
1648			))),
1649		}
1650	}
1651}
1652impl XsdValue for DecimalValue {
1653	fn datatype(&self) -> Datatype {
1654		self.datatype().into()
1655	}
1656}
1657impl fmt::Display for DecimalValue {
1658	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1659		match self {
1660			Self::Decimal(v) => v.fmt(f),
1661			Self::Integer(v) => v.fmt(f),
1662			Self::NonPositiveInteger(v) => v.fmt(f),
1663			Self::NegativeInteger(v) => v.fmt(f),
1664			Self::NonNegativeInteger(v) => v.fmt(f),
1665			Self::PositiveInteger(v) => v.fmt(f),
1666			Self::UnsignedLong(v) => v.fmt(f),
1667			Self::UnsignedInt(v) => v.fmt(f),
1668			Self::UnsignedShort(v) => v.fmt(f),
1669			Self::UnsignedByte(v) => v.fmt(f),
1670			Self::Long(v) => v.fmt(f),
1671			Self::Int(v) => v.fmt(f),
1672			Self::Short(v) => v.fmt(f),
1673			Self::Byte(v) => v.fmt(f),
1674		}
1675	}
1676}
1677impl From<IntegerValue> for DecimalValue {
1678	fn from(value: IntegerValue) -> Self {
1679		match value {
1680			IntegerValue::Integer(value) => Self::Integer(value),
1681			IntegerValue::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1682			IntegerValue::NegativeInteger(value) => Self::NegativeInteger(value),
1683			IntegerValue::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1684			IntegerValue::PositiveInteger(value) => Self::PositiveInteger(value),
1685			IntegerValue::UnsignedLong(value) => Self::UnsignedLong(value),
1686			IntegerValue::UnsignedInt(value) => Self::UnsignedInt(value),
1687			IntegerValue::UnsignedShort(value) => Self::UnsignedShort(value),
1688			IntegerValue::UnsignedByte(value) => Self::UnsignedByte(value),
1689			IntegerValue::Long(value) => Self::Long(value),
1690			IntegerValue::Int(value) => Self::Int(value),
1691			IntegerValue::Short(value) => Self::Short(value),
1692			IntegerValue::Byte(value) => Self::Byte(value),
1693		}
1694	}
1695}
1696impl From<NonPositiveIntegerValue> for DecimalValue {
1697	fn from(value: NonPositiveIntegerValue) -> Self {
1698		match value {
1699			NonPositiveIntegerValue::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
1700			NonPositiveIntegerValue::NegativeInteger(value) => Self::NegativeInteger(value),
1701		}
1702	}
1703}
1704impl From<NonNegativeIntegerValue> for DecimalValue {
1705	fn from(value: NonNegativeIntegerValue) -> Self {
1706		match value {
1707			NonNegativeIntegerValue::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
1708			NonNegativeIntegerValue::PositiveInteger(value) => Self::PositiveInteger(value),
1709			NonNegativeIntegerValue::UnsignedLong(value) => Self::UnsignedLong(value),
1710			NonNegativeIntegerValue::UnsignedInt(value) => Self::UnsignedInt(value),
1711			NonNegativeIntegerValue::UnsignedShort(value) => Self::UnsignedShort(value),
1712			NonNegativeIntegerValue::UnsignedByte(value) => Self::UnsignedByte(value),
1713		}
1714	}
1715}
1716impl From<UnsignedLongValue> for DecimalValue {
1717	fn from(value: UnsignedLongValue) -> Self {
1718		match value {
1719			UnsignedLongValue::UnsignedLong(value) => Self::UnsignedLong(value),
1720			UnsignedLongValue::UnsignedInt(value) => Self::UnsignedInt(value),
1721			UnsignedLongValue::UnsignedShort(value) => Self::UnsignedShort(value),
1722			UnsignedLongValue::UnsignedByte(value) => Self::UnsignedByte(value),
1723		}
1724	}
1725}
1726impl From<UnsignedIntValue> for DecimalValue {
1727	fn from(value: UnsignedIntValue) -> Self {
1728		match value {
1729			UnsignedIntValue::UnsignedInt(value) => Self::UnsignedInt(value),
1730			UnsignedIntValue::UnsignedShort(value) => Self::UnsignedShort(value),
1731			UnsignedIntValue::UnsignedByte(value) => Self::UnsignedByte(value),
1732		}
1733	}
1734}
1735impl From<UnsignedShortValue> for DecimalValue {
1736	fn from(value: UnsignedShortValue) -> Self {
1737		match value {
1738			UnsignedShortValue::UnsignedShort(value) => Self::UnsignedShort(value),
1739			UnsignedShortValue::UnsignedByte(value) => Self::UnsignedByte(value),
1740		}
1741	}
1742}
1743impl From<LongValue> for DecimalValue {
1744	fn from(value: LongValue) -> Self {
1745		match value {
1746			LongValue::Long(value) => Self::Long(value),
1747			LongValue::Int(value) => Self::Int(value),
1748			LongValue::Short(value) => Self::Short(value),
1749			LongValue::Byte(value) => Self::Byte(value),
1750		}
1751	}
1752}
1753impl From<IntValue> for DecimalValue {
1754	fn from(value: IntValue) -> Self {
1755		match value {
1756			IntValue::Int(value) => Self::Int(value),
1757			IntValue::Short(value) => Self::Short(value),
1758			IntValue::Byte(value) => Self::Byte(value),
1759		}
1760	}
1761}
1762impl From<ShortValue> for DecimalValue {
1763	fn from(value: ShortValue) -> Self {
1764		match value {
1765			ShortValue::Short(value) => Self::Short(value),
1766			ShortValue::Byte(value) => Self::Byte(value),
1767		}
1768	}
1769}
1770impl TryFrom<DecimalValue> for IntegerValue {
1771	type Error = DecimalValue;
1772	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1773		match value {
1774			DecimalValue::Integer(value) => Ok(Self::Integer(value)),
1775			DecimalValue::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1776			DecimalValue::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1777			DecimalValue::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1778			DecimalValue::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1779			DecimalValue::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1780			DecimalValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1781			DecimalValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1782			DecimalValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1783			DecimalValue::Long(value) => Ok(Self::Long(value)),
1784			DecimalValue::Int(value) => Ok(Self::Int(value)),
1785			DecimalValue::Short(value) => Ok(Self::Short(value)),
1786			DecimalValue::Byte(value) => Ok(Self::Byte(value)),
1787			other => Err(other),
1788		}
1789	}
1790}
1791impl TryFrom<DecimalValue> for NonPositiveIntegerValue {
1792	type Error = DecimalValue;
1793	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1794		match value {
1795			DecimalValue::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
1796			DecimalValue::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
1797			other => Err(other),
1798		}
1799	}
1800}
1801impl TryFrom<DecimalValue> for NonNegativeIntegerValue {
1802	type Error = DecimalValue;
1803	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1804		match value {
1805			DecimalValue::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
1806			DecimalValue::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
1807			DecimalValue::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1808			DecimalValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1809			DecimalValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1810			DecimalValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1811			other => Err(other),
1812		}
1813	}
1814}
1815impl TryFrom<DecimalValue> for UnsignedLongValue {
1816	type Error = DecimalValue;
1817	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1818		match value {
1819			DecimalValue::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
1820			DecimalValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1821			DecimalValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1822			DecimalValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1823			other => Err(other),
1824		}
1825	}
1826}
1827impl TryFrom<DecimalValue> for UnsignedIntValue {
1828	type Error = DecimalValue;
1829	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1830		match value {
1831			DecimalValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
1832			DecimalValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1833			DecimalValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1834			other => Err(other),
1835		}
1836	}
1837}
1838impl TryFrom<DecimalValue> for UnsignedShortValue {
1839	type Error = DecimalValue;
1840	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1841		match value {
1842			DecimalValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
1843			DecimalValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
1844			other => Err(other),
1845		}
1846	}
1847}
1848impl TryFrom<DecimalValue> for LongValue {
1849	type Error = DecimalValue;
1850	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1851		match value {
1852			DecimalValue::Long(value) => Ok(Self::Long(value)),
1853			DecimalValue::Int(value) => Ok(Self::Int(value)),
1854			DecimalValue::Short(value) => Ok(Self::Short(value)),
1855			DecimalValue::Byte(value) => Ok(Self::Byte(value)),
1856			other => Err(other),
1857		}
1858	}
1859}
1860impl TryFrom<DecimalValue> for IntValue {
1861	type Error = DecimalValue;
1862	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1863		match value {
1864			DecimalValue::Int(value) => Ok(Self::Int(value)),
1865			DecimalValue::Short(value) => Ok(Self::Short(value)),
1866			DecimalValue::Byte(value) => Ok(Self::Byte(value)),
1867			other => Err(other),
1868		}
1869	}
1870}
1871impl TryFrom<DecimalValue> for ShortValue {
1872	type Error = DecimalValue;
1873	fn try_from(value: DecimalValue) -> Result<Self, DecimalValue> {
1874		match value {
1875			DecimalValue::Short(value) => Ok(Self::Short(value)),
1876			DecimalValue::Byte(value) => Ok(Self::Byte(value)),
1877			other => Err(other),
1878		}
1879	}
1880}
1881/// [`Integer`] datatype variants.
1882#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1883pub enum IntegerDatatype {
1884	Integer,
1885	NonPositiveInteger(NonPositiveIntegerDatatype),
1886	NonNegativeInteger(NonNegativeIntegerDatatype),
1887	Long(LongDatatype),
1888}
1889impl IntegerDatatype {
1890	pub fn from_iri(iri: &Iri) -> Option<Self> {
1891		if iri == XSD_INTEGER {
1892			return Some(Self::Integer);
1893		}
1894		if let Some(t) = NonPositiveIntegerDatatype::from_iri(iri) {
1895			return Some(Self::NonPositiveInteger(t));
1896		}
1897		if let Some(t) = NonNegativeIntegerDatatype::from_iri(iri) {
1898			return Some(Self::NonNegativeInteger(t));
1899		}
1900		if let Some(t) = LongDatatype::from_iri(iri) {
1901			return Some(Self::Long(t));
1902		}
1903		None
1904	}
1905	pub fn iri(&self) -> &'static Iri {
1906		match self {
1907			Self::Integer => XSD_INTEGER,
1908			Self::NonPositiveInteger(t) => t.iri(),
1909			Self::NonNegativeInteger(t) => t.iri(),
1910			Self::Long(t) => t.iri(),
1911		}
1912	}
1913	pub fn parse(&self, value: &str) -> Result<IntegerValue, ParseError> {
1914		match self {
1915			Self::Integer => ParseXsd::parse_xsd(value)
1916				.map(IntegerValue::Integer)
1917				.map_err(|_| ParseError),
1918			Self::NonPositiveInteger(t) => t.parse(value).map(Into::into),
1919			Self::NonNegativeInteger(t) => t.parse(value).map(Into::into),
1920			Self::Long(t) => t.parse(value).map(Into::into),
1921		}
1922	}
1923}
1924impl From<NonPositiveIntegerDatatype> for IntegerDatatype {
1925	fn from(value: NonPositiveIntegerDatatype) -> Self {
1926		Self::NonPositiveInteger(value)
1927	}
1928}
1929impl TryFrom<IntegerDatatype> for NonPositiveIntegerDatatype {
1930	type Error = IntegerDatatype;
1931	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
1932		match value {
1933			IntegerDatatype::NonPositiveInteger(value) => Ok(value),
1934			other => Err(other),
1935		}
1936	}
1937}
1938impl From<NonNegativeIntegerDatatype> for IntegerDatatype {
1939	fn from(value: NonNegativeIntegerDatatype) -> Self {
1940		Self::NonNegativeInteger(value)
1941	}
1942}
1943impl From<UnsignedLongDatatype> for IntegerDatatype {
1944	fn from(value: UnsignedLongDatatype) -> Self {
1945		Self::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(value))
1946	}
1947}
1948impl From<UnsignedIntDatatype> for IntegerDatatype {
1949	fn from(value: UnsignedIntDatatype) -> Self {
1950		Self::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1951			UnsignedLongDatatype::UnsignedInt(value),
1952		))
1953	}
1954}
1955impl From<UnsignedShortDatatype> for IntegerDatatype {
1956	fn from(value: UnsignedShortDatatype) -> Self {
1957		Self::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1958			UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(value)),
1959		))
1960	}
1961}
1962impl TryFrom<IntegerDatatype> for NonNegativeIntegerDatatype {
1963	type Error = IntegerDatatype;
1964	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
1965		match value {
1966			IntegerDatatype::NonNegativeInteger(value) => Ok(value),
1967			other => Err(other),
1968		}
1969	}
1970}
1971impl TryFrom<IntegerDatatype> for UnsignedLongDatatype {
1972	type Error = IntegerDatatype;
1973	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
1974		match value {
1975			IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1976				value,
1977			)) => Ok(value),
1978			other => Err(other),
1979		}
1980	}
1981}
1982impl TryFrom<IntegerDatatype> for UnsignedIntDatatype {
1983	type Error = IntegerDatatype;
1984	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
1985		match value {
1986			IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1987				UnsignedLongDatatype::UnsignedInt(value),
1988			)) => Ok(value),
1989			other => Err(other),
1990		}
1991	}
1992}
1993impl TryFrom<IntegerDatatype> for UnsignedShortDatatype {
1994	type Error = IntegerDatatype;
1995	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
1996		match value {
1997			IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
1998				UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(value)),
1999			)) => Ok(value),
2000			other => Err(other),
2001		}
2002	}
2003}
2004impl From<LongDatatype> for IntegerDatatype {
2005	fn from(value: LongDatatype) -> Self {
2006		Self::Long(value)
2007	}
2008}
2009impl From<IntDatatype> for IntegerDatatype {
2010	fn from(value: IntDatatype) -> Self {
2011		Self::Long(LongDatatype::Int(value))
2012	}
2013}
2014impl From<ShortDatatype> for IntegerDatatype {
2015	fn from(value: ShortDatatype) -> Self {
2016		Self::Long(LongDatatype::Int(IntDatatype::Short(value)))
2017	}
2018}
2019impl TryFrom<IntegerDatatype> for LongDatatype {
2020	type Error = IntegerDatatype;
2021	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
2022		match value {
2023			IntegerDatatype::Long(value) => Ok(value),
2024			other => Err(other),
2025		}
2026	}
2027}
2028impl TryFrom<IntegerDatatype> for IntDatatype {
2029	type Error = IntegerDatatype;
2030	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
2031		match value {
2032			IntegerDatatype::Long(LongDatatype::Int(value)) => Ok(value),
2033			other => Err(other),
2034		}
2035	}
2036}
2037impl TryFrom<IntegerDatatype> for ShortDatatype {
2038	type Error = IntegerDatatype;
2039	fn try_from(value: IntegerDatatype) -> Result<Self, IntegerDatatype> {
2040		match value {
2041			IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Short(value))) => Ok(value),
2042			other => Err(other),
2043		}
2044	}
2045}
2046/// Any specialized [`Decimal`] value reference.
2047#[derive(Debug, Clone, Copy)]
2048pub enum DecimalValueRef<'a> {
2049	Decimal(&'a Decimal),
2050	Integer(&'a Integer),
2051	NonPositiveInteger(&'a NonPositiveInteger),
2052	NegativeInteger(&'a NegativeInteger),
2053	NonNegativeInteger(&'a NonNegativeInteger),
2054	PositiveInteger(&'a PositiveInteger),
2055	UnsignedLong(UnsignedLong),
2056	UnsignedInt(UnsignedInt),
2057	UnsignedShort(UnsignedShort),
2058	UnsignedByte(UnsignedByte),
2059	Long(Long),
2060	Int(Int),
2061	Short(Short),
2062	Byte(Byte),
2063}
2064impl DecimalValue {
2065	pub fn as_ref(&self) -> DecimalValueRef {
2066		match self {
2067			Self::Decimal(value) => DecimalValueRef::Decimal(value),
2068			Self::Integer(value) => DecimalValueRef::Integer(value),
2069			Self::NonPositiveInteger(value) => DecimalValueRef::NonPositiveInteger(value),
2070			Self::NegativeInteger(value) => DecimalValueRef::NegativeInteger(value),
2071			Self::NonNegativeInteger(value) => DecimalValueRef::NonNegativeInteger(value),
2072			Self::PositiveInteger(value) => DecimalValueRef::PositiveInteger(value),
2073			Self::UnsignedLong(value) => DecimalValueRef::UnsignedLong(*value),
2074			Self::UnsignedInt(value) => DecimalValueRef::UnsignedInt(*value),
2075			Self::UnsignedShort(value) => DecimalValueRef::UnsignedShort(*value),
2076			Self::UnsignedByte(value) => DecimalValueRef::UnsignedByte(*value),
2077			Self::Long(value) => DecimalValueRef::Long(*value),
2078			Self::Int(value) => DecimalValueRef::Int(*value),
2079			Self::Short(value) => DecimalValueRef::Short(*value),
2080			Self::Byte(value) => DecimalValueRef::Byte(*value),
2081		}
2082	}
2083}
2084impl<'a> DecimalValueRef<'a> {
2085	pub fn datatype(&self) -> DecimalDatatype {
2086		match self {
2087			Self::Decimal(_) => DecimalDatatype::Decimal,
2088			Self::Integer(_) => DecimalDatatype::Integer(IntegerDatatype::Integer),
2089			Self::NonPositiveInteger(_) => DecimalDatatype::Integer(
2090				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NonPositiveInteger),
2091			),
2092			Self::NegativeInteger(_) => DecimalDatatype::Integer(
2093				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NegativeInteger),
2094			),
2095			Self::NonNegativeInteger(_) => DecimalDatatype::Integer(
2096				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::NonNegativeInteger),
2097			),
2098			Self::PositiveInteger(_) => DecimalDatatype::Integer(
2099				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::PositiveInteger),
2100			),
2101			Self::UnsignedLong(_) => DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
2102				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedLong),
2103			)),
2104			Self::UnsignedInt(_) => DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
2105				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2106					UnsignedIntDatatype::UnsignedInt,
2107				)),
2108			)),
2109			Self::UnsignedShort(_) => {
2110				DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
2111					NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2112						UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
2113					)),
2114				))
2115			}
2116			Self::UnsignedByte(_) => DecimalDatatype::Integer(IntegerDatatype::NonNegativeInteger(
2117				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2118					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
2119				)),
2120			)),
2121			Self::Long(_) => DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Long)),
2122			Self::Int(_) => {
2123				DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Int)))
2124			}
2125			Self::Short(_) => DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(
2126				IntDatatype::Short(ShortDatatype::Short),
2127			))),
2128			Self::Byte(_) => DecimalDatatype::Integer(IntegerDatatype::Long(LongDatatype::Int(
2129				IntDatatype::Short(ShortDatatype::Byte),
2130			))),
2131		}
2132	}
2133	pub fn cloned(&self) -> DecimalValue {
2134		match *self {
2135			Self::Decimal(value) => DecimalValue::Decimal(value.to_owned()),
2136			Self::Integer(value) => DecimalValue::Integer(value.to_owned()),
2137			Self::NonPositiveInteger(value) => DecimalValue::NonPositiveInteger(value.to_owned()),
2138			Self::NegativeInteger(value) => DecimalValue::NegativeInteger(value.to_owned()),
2139			Self::NonNegativeInteger(value) => DecimalValue::NonNegativeInteger(value.to_owned()),
2140			Self::PositiveInteger(value) => DecimalValue::PositiveInteger(value.to_owned()),
2141			Self::UnsignedLong(value) => DecimalValue::UnsignedLong(value),
2142			Self::UnsignedInt(value) => DecimalValue::UnsignedInt(value),
2143			Self::UnsignedShort(value) => DecimalValue::UnsignedShort(value),
2144			Self::UnsignedByte(value) => DecimalValue::UnsignedByte(value),
2145			Self::Long(value) => DecimalValue::Long(value),
2146			Self::Int(value) => DecimalValue::Int(value),
2147			Self::Short(value) => DecimalValue::Short(value),
2148			Self::Byte(value) => DecimalValue::Byte(value),
2149		}
2150	}
2151}
2152impl<'a> XsdValue for DecimalValueRef<'a> {
2153	fn datatype(&self) -> Datatype {
2154		self.datatype().into()
2155	}
2156}
2157impl<'a> fmt::Display for DecimalValueRef<'a> {
2158	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2159		match self {
2160			Self::Decimal(v) => v.fmt(f),
2161			Self::Integer(v) => v.fmt(f),
2162			Self::NonPositiveInteger(v) => v.fmt(f),
2163			Self::NegativeInteger(v) => v.fmt(f),
2164			Self::NonNegativeInteger(v) => v.fmt(f),
2165			Self::PositiveInteger(v) => v.fmt(f),
2166			Self::UnsignedLong(v) => v.fmt(f),
2167			Self::UnsignedInt(v) => v.fmt(f),
2168			Self::UnsignedShort(v) => v.fmt(f),
2169			Self::UnsignedByte(v) => v.fmt(f),
2170			Self::Long(v) => v.fmt(f),
2171			Self::Int(v) => v.fmt(f),
2172			Self::Short(v) => v.fmt(f),
2173			Self::Byte(v) => v.fmt(f),
2174		}
2175	}
2176}
2177impl<'a> From<IntegerValueRef<'a>> for DecimalValueRef<'a> {
2178	fn from(value: IntegerValueRef<'a>) -> Self {
2179		match value {
2180			IntegerValueRef::Integer(value) => Self::Integer(value),
2181			IntegerValueRef::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
2182			IntegerValueRef::NegativeInteger(value) => Self::NegativeInteger(value),
2183			IntegerValueRef::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
2184			IntegerValueRef::PositiveInteger(value) => Self::PositiveInteger(value),
2185			IntegerValueRef::UnsignedLong(value) => Self::UnsignedLong(value),
2186			IntegerValueRef::UnsignedInt(value) => Self::UnsignedInt(value),
2187			IntegerValueRef::UnsignedShort(value) => Self::UnsignedShort(value),
2188			IntegerValueRef::UnsignedByte(value) => Self::UnsignedByte(value),
2189			IntegerValueRef::Long(value) => Self::Long(value),
2190			IntegerValueRef::Int(value) => Self::Int(value),
2191			IntegerValueRef::Short(value) => Self::Short(value),
2192			IntegerValueRef::Byte(value) => Self::Byte(value),
2193		}
2194	}
2195}
2196impl<'a> From<NonPositiveIntegerValueRef<'a>> for DecimalValueRef<'a> {
2197	fn from(value: NonPositiveIntegerValueRef<'a>) -> Self {
2198		match value {
2199			NonPositiveIntegerValueRef::NonPositiveInteger(value) => {
2200				Self::NonPositiveInteger(value)
2201			}
2202			NonPositiveIntegerValueRef::NegativeInteger(value) => Self::NegativeInteger(value),
2203		}
2204	}
2205}
2206impl<'a> From<NonNegativeIntegerValueRef<'a>> for DecimalValueRef<'a> {
2207	fn from(value: NonNegativeIntegerValueRef<'a>) -> Self {
2208		match value {
2209			NonNegativeIntegerValueRef::NonNegativeInteger(value) => {
2210				Self::NonNegativeInteger(value)
2211			}
2212			NonNegativeIntegerValueRef::PositiveInteger(value) => Self::PositiveInteger(value),
2213			NonNegativeIntegerValueRef::UnsignedLong(value) => Self::UnsignedLong(value),
2214			NonNegativeIntegerValueRef::UnsignedInt(value) => Self::UnsignedInt(value),
2215			NonNegativeIntegerValueRef::UnsignedShort(value) => Self::UnsignedShort(value),
2216			NonNegativeIntegerValueRef::UnsignedByte(value) => Self::UnsignedByte(value),
2217		}
2218	}
2219}
2220impl<'a> TryFrom<DecimalValueRef<'a>> for IntegerValueRef<'a> {
2221	type Error = DecimalValueRef<'a>;
2222	fn try_from(value: DecimalValueRef<'a>) -> Result<Self, DecimalValueRef<'a>> {
2223		match value {
2224			DecimalValueRef::Integer(value) => Ok(Self::Integer(value)),
2225			DecimalValueRef::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
2226			DecimalValueRef::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
2227			DecimalValueRef::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
2228			DecimalValueRef::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
2229			DecimalValueRef::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
2230			DecimalValueRef::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
2231			DecimalValueRef::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2232			DecimalValueRef::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2233			DecimalValueRef::Long(value) => Ok(Self::Long(value)),
2234			DecimalValueRef::Int(value) => Ok(Self::Int(value)),
2235			DecimalValueRef::Short(value) => Ok(Self::Short(value)),
2236			DecimalValueRef::Byte(value) => Ok(Self::Byte(value)),
2237			other => Err(other),
2238		}
2239	}
2240}
2241impl<'a> TryFrom<DecimalValueRef<'a>> for NonPositiveIntegerValueRef<'a> {
2242	type Error = DecimalValueRef<'a>;
2243	fn try_from(value: DecimalValueRef<'a>) -> Result<Self, DecimalValueRef<'a>> {
2244		match value {
2245			DecimalValueRef::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
2246			DecimalValueRef::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
2247			other => Err(other),
2248		}
2249	}
2250}
2251impl<'a> TryFrom<DecimalValueRef<'a>> for NonNegativeIntegerValueRef<'a> {
2252	type Error = DecimalValueRef<'a>;
2253	fn try_from(value: DecimalValueRef<'a>) -> Result<Self, DecimalValueRef<'a>> {
2254		match value {
2255			DecimalValueRef::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
2256			DecimalValueRef::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
2257			DecimalValueRef::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
2258			DecimalValueRef::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
2259			DecimalValueRef::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2260			DecimalValueRef::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2261			other => Err(other),
2262		}
2263	}
2264}
2265/// Any specialized [`Integer`] value.
2266#[derive(Debug, Clone)]
2267pub enum IntegerValue {
2268	Integer(Integer),
2269	NonPositiveInteger(NonPositiveInteger),
2270	NegativeInteger(NegativeInteger),
2271	NonNegativeInteger(NonNegativeInteger),
2272	PositiveInteger(PositiveInteger),
2273	UnsignedLong(UnsignedLong),
2274	UnsignedInt(UnsignedInt),
2275	UnsignedShort(UnsignedShort),
2276	UnsignedByte(UnsignedByte),
2277	Long(Long),
2278	Int(Int),
2279	Short(Short),
2280	Byte(Byte),
2281}
2282impl IntegerValue {
2283	pub fn datatype(&self) -> IntegerDatatype {
2284		match self {
2285			Self::Integer(_) => IntegerDatatype::Integer,
2286			Self::NonPositiveInteger(_) => {
2287				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NonPositiveInteger)
2288			}
2289			Self::NegativeInteger(_) => {
2290				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NegativeInteger)
2291			}
2292			Self::NonNegativeInteger(_) => {
2293				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::NonNegativeInteger)
2294			}
2295			Self::PositiveInteger(_) => {
2296				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::PositiveInteger)
2297			}
2298			Self::UnsignedLong(_) => IntegerDatatype::NonNegativeInteger(
2299				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedLong),
2300			),
2301			Self::UnsignedInt(_) => {
2302				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
2303					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt),
2304				))
2305			}
2306			Self::UnsignedShort(_) => IntegerDatatype::NonNegativeInteger(
2307				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2308					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
2309				)),
2310			),
2311			Self::UnsignedByte(_) => IntegerDatatype::NonNegativeInteger(
2312				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2313					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
2314				)),
2315			),
2316			Self::Long(_) => IntegerDatatype::Long(LongDatatype::Long),
2317			Self::Int(_) => IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Int)),
2318			Self::Short(_) => {
2319				IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Short(ShortDatatype::Short)))
2320			}
2321			Self::Byte(_) => {
2322				IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Short(ShortDatatype::Byte)))
2323			}
2324		}
2325	}
2326}
2327impl XsdValue for IntegerValue {
2328	fn datatype(&self) -> Datatype {
2329		self.datatype().into()
2330	}
2331}
2332impl fmt::Display for IntegerValue {
2333	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2334		match self {
2335			Self::Integer(v) => v.fmt(f),
2336			Self::NonPositiveInteger(v) => v.fmt(f),
2337			Self::NegativeInteger(v) => v.fmt(f),
2338			Self::NonNegativeInteger(v) => v.fmt(f),
2339			Self::PositiveInteger(v) => v.fmt(f),
2340			Self::UnsignedLong(v) => v.fmt(f),
2341			Self::UnsignedInt(v) => v.fmt(f),
2342			Self::UnsignedShort(v) => v.fmt(f),
2343			Self::UnsignedByte(v) => v.fmt(f),
2344			Self::Long(v) => v.fmt(f),
2345			Self::Int(v) => v.fmt(f),
2346			Self::Short(v) => v.fmt(f),
2347			Self::Byte(v) => v.fmt(f),
2348		}
2349	}
2350}
2351impl From<NonPositiveIntegerValue> for IntegerValue {
2352	fn from(value: NonPositiveIntegerValue) -> Self {
2353		match value {
2354			NonPositiveIntegerValue::NonPositiveInteger(value) => Self::NonPositiveInteger(value),
2355			NonPositiveIntegerValue::NegativeInteger(value) => Self::NegativeInteger(value),
2356		}
2357	}
2358}
2359impl TryFrom<IntegerValue> for NonPositiveIntegerValue {
2360	type Error = IntegerValue;
2361	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2362		match value {
2363			IntegerValue::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
2364			IntegerValue::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
2365			other => Err(other),
2366		}
2367	}
2368}
2369/// [`NonPositiveInteger`] datatype variants.
2370#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2371pub enum NonPositiveIntegerDatatype {
2372	NonPositiveInteger,
2373	NegativeInteger,
2374}
2375impl NonPositiveIntegerDatatype {
2376	pub fn from_iri(iri: &Iri) -> Option<Self> {
2377		if iri == XSD_NON_POSITIVE_INTEGER {
2378			return Some(Self::NonPositiveInteger);
2379		}
2380		if iri == XSD_NEGATIVE_INTEGER {
2381			return Some(Self::NegativeInteger);
2382		}
2383		None
2384	}
2385	pub fn iri(&self) -> &'static Iri {
2386		match self {
2387			Self::NonPositiveInteger => XSD_NON_POSITIVE_INTEGER,
2388			Self::NegativeInteger => XSD_NEGATIVE_INTEGER,
2389		}
2390	}
2391	pub fn parse(&self, value: &str) -> Result<NonPositiveIntegerValue, ParseError> {
2392		match self {
2393			Self::NonPositiveInteger => ParseXsd::parse_xsd(value)
2394				.map(NonPositiveIntegerValue::NonPositiveInteger)
2395				.map_err(|_| ParseError),
2396			Self::NegativeInteger => ParseXsd::parse_xsd(value)
2397				.map(NonPositiveIntegerValue::NegativeInteger)
2398				.map_err(|_| ParseError),
2399		}
2400	}
2401}
2402impl From<NonNegativeIntegerValue> for IntegerValue {
2403	fn from(value: NonNegativeIntegerValue) -> Self {
2404		match value {
2405			NonNegativeIntegerValue::NonNegativeInteger(value) => Self::NonNegativeInteger(value),
2406			NonNegativeIntegerValue::PositiveInteger(value) => Self::PositiveInteger(value),
2407			NonNegativeIntegerValue::UnsignedLong(value) => Self::UnsignedLong(value),
2408			NonNegativeIntegerValue::UnsignedInt(value) => Self::UnsignedInt(value),
2409			NonNegativeIntegerValue::UnsignedShort(value) => Self::UnsignedShort(value),
2410			NonNegativeIntegerValue::UnsignedByte(value) => Self::UnsignedByte(value),
2411		}
2412	}
2413}
2414impl From<UnsignedLongValue> for IntegerValue {
2415	fn from(value: UnsignedLongValue) -> Self {
2416		match value {
2417			UnsignedLongValue::UnsignedLong(value) => Self::UnsignedLong(value),
2418			UnsignedLongValue::UnsignedInt(value) => Self::UnsignedInt(value),
2419			UnsignedLongValue::UnsignedShort(value) => Self::UnsignedShort(value),
2420			UnsignedLongValue::UnsignedByte(value) => Self::UnsignedByte(value),
2421		}
2422	}
2423}
2424impl From<UnsignedIntValue> for IntegerValue {
2425	fn from(value: UnsignedIntValue) -> Self {
2426		match value {
2427			UnsignedIntValue::UnsignedInt(value) => Self::UnsignedInt(value),
2428			UnsignedIntValue::UnsignedShort(value) => Self::UnsignedShort(value),
2429			UnsignedIntValue::UnsignedByte(value) => Self::UnsignedByte(value),
2430		}
2431	}
2432}
2433impl From<UnsignedShortValue> for IntegerValue {
2434	fn from(value: UnsignedShortValue) -> Self {
2435		match value {
2436			UnsignedShortValue::UnsignedShort(value) => Self::UnsignedShort(value),
2437			UnsignedShortValue::UnsignedByte(value) => Self::UnsignedByte(value),
2438		}
2439	}
2440}
2441impl TryFrom<IntegerValue> for NonNegativeIntegerValue {
2442	type Error = IntegerValue;
2443	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2444		match value {
2445			IntegerValue::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
2446			IntegerValue::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
2447			IntegerValue::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
2448			IntegerValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
2449			IntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2450			IntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2451			other => Err(other),
2452		}
2453	}
2454}
2455impl TryFrom<IntegerValue> for UnsignedLongValue {
2456	type Error = IntegerValue;
2457	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2458		match value {
2459			IntegerValue::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
2460			IntegerValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
2461			IntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2462			IntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2463			other => Err(other),
2464		}
2465	}
2466}
2467impl TryFrom<IntegerValue> for UnsignedIntValue {
2468	type Error = IntegerValue;
2469	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2470		match value {
2471			IntegerValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
2472			IntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2473			IntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2474			other => Err(other),
2475		}
2476	}
2477}
2478impl TryFrom<IntegerValue> for UnsignedShortValue {
2479	type Error = IntegerValue;
2480	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2481		match value {
2482			IntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2483			IntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2484			other => Err(other),
2485		}
2486	}
2487}
2488/// [`NonNegativeInteger`] datatype variants.
2489#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2490pub enum NonNegativeIntegerDatatype {
2491	NonNegativeInteger,
2492	PositiveInteger,
2493	UnsignedLong(UnsignedLongDatatype),
2494}
2495impl NonNegativeIntegerDatatype {
2496	pub fn from_iri(iri: &Iri) -> Option<Self> {
2497		if iri == XSD_NON_NEGATIVE_INTEGER {
2498			return Some(Self::NonNegativeInteger);
2499		}
2500		if iri == XSD_POSITIVE_INTEGER {
2501			return Some(Self::PositiveInteger);
2502		}
2503		if let Some(t) = UnsignedLongDatatype::from_iri(iri) {
2504			return Some(Self::UnsignedLong(t));
2505		}
2506		None
2507	}
2508	pub fn iri(&self) -> &'static Iri {
2509		match self {
2510			Self::NonNegativeInteger => XSD_NON_NEGATIVE_INTEGER,
2511			Self::PositiveInteger => XSD_POSITIVE_INTEGER,
2512			Self::UnsignedLong(t) => t.iri(),
2513		}
2514	}
2515	pub fn parse(&self, value: &str) -> Result<NonNegativeIntegerValue, ParseError> {
2516		match self {
2517			Self::NonNegativeInteger => ParseXsd::parse_xsd(value)
2518				.map(NonNegativeIntegerValue::NonNegativeInteger)
2519				.map_err(|_| ParseError),
2520			Self::PositiveInteger => ParseXsd::parse_xsd(value)
2521				.map(NonNegativeIntegerValue::PositiveInteger)
2522				.map_err(|_| ParseError),
2523			Self::UnsignedLong(t) => t.parse(value).map(Into::into),
2524		}
2525	}
2526}
2527impl From<UnsignedLongDatatype> for NonNegativeIntegerDatatype {
2528	fn from(value: UnsignedLongDatatype) -> Self {
2529		Self::UnsignedLong(value)
2530	}
2531}
2532impl From<UnsignedIntDatatype> for NonNegativeIntegerDatatype {
2533	fn from(value: UnsignedIntDatatype) -> Self {
2534		Self::UnsignedLong(UnsignedLongDatatype::UnsignedInt(value))
2535	}
2536}
2537impl From<UnsignedShortDatatype> for NonNegativeIntegerDatatype {
2538	fn from(value: UnsignedShortDatatype) -> Self {
2539		Self::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2540			UnsignedIntDatatype::UnsignedShort(value),
2541		))
2542	}
2543}
2544impl TryFrom<NonNegativeIntegerDatatype> for UnsignedLongDatatype {
2545	type Error = NonNegativeIntegerDatatype;
2546	fn try_from(value: NonNegativeIntegerDatatype) -> Result<Self, NonNegativeIntegerDatatype> {
2547		match value {
2548			NonNegativeIntegerDatatype::UnsignedLong(value) => Ok(value),
2549			other => Err(other),
2550		}
2551	}
2552}
2553impl TryFrom<NonNegativeIntegerDatatype> for UnsignedIntDatatype {
2554	type Error = NonNegativeIntegerDatatype;
2555	fn try_from(value: NonNegativeIntegerDatatype) -> Result<Self, NonNegativeIntegerDatatype> {
2556		match value {
2557			NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(value)) => {
2558				Ok(value)
2559			}
2560			other => Err(other),
2561		}
2562	}
2563}
2564impl TryFrom<NonNegativeIntegerDatatype> for UnsignedShortDatatype {
2565	type Error = NonNegativeIntegerDatatype;
2566	fn try_from(value: NonNegativeIntegerDatatype) -> Result<Self, NonNegativeIntegerDatatype> {
2567		match value {
2568			NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2569				UnsignedIntDatatype::UnsignedShort(value),
2570			)) => Ok(value),
2571			other => Err(other),
2572		}
2573	}
2574}
2575impl From<LongValue> for IntegerValue {
2576	fn from(value: LongValue) -> Self {
2577		match value {
2578			LongValue::Long(value) => Self::Long(value),
2579			LongValue::Int(value) => Self::Int(value),
2580			LongValue::Short(value) => Self::Short(value),
2581			LongValue::Byte(value) => Self::Byte(value),
2582		}
2583	}
2584}
2585impl From<IntValue> for IntegerValue {
2586	fn from(value: IntValue) -> Self {
2587		match value {
2588			IntValue::Int(value) => Self::Int(value),
2589			IntValue::Short(value) => Self::Short(value),
2590			IntValue::Byte(value) => Self::Byte(value),
2591		}
2592	}
2593}
2594impl From<ShortValue> for IntegerValue {
2595	fn from(value: ShortValue) -> Self {
2596		match value {
2597			ShortValue::Short(value) => Self::Short(value),
2598			ShortValue::Byte(value) => Self::Byte(value),
2599		}
2600	}
2601}
2602impl TryFrom<IntegerValue> for LongValue {
2603	type Error = IntegerValue;
2604	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2605		match value {
2606			IntegerValue::Long(value) => Ok(Self::Long(value)),
2607			IntegerValue::Int(value) => Ok(Self::Int(value)),
2608			IntegerValue::Short(value) => Ok(Self::Short(value)),
2609			IntegerValue::Byte(value) => Ok(Self::Byte(value)),
2610			other => Err(other),
2611		}
2612	}
2613}
2614impl TryFrom<IntegerValue> for IntValue {
2615	type Error = IntegerValue;
2616	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2617		match value {
2618			IntegerValue::Int(value) => Ok(Self::Int(value)),
2619			IntegerValue::Short(value) => Ok(Self::Short(value)),
2620			IntegerValue::Byte(value) => Ok(Self::Byte(value)),
2621			other => Err(other),
2622		}
2623	}
2624}
2625impl TryFrom<IntegerValue> for ShortValue {
2626	type Error = IntegerValue;
2627	fn try_from(value: IntegerValue) -> Result<Self, IntegerValue> {
2628		match value {
2629			IntegerValue::Short(value) => Ok(Self::Short(value)),
2630			IntegerValue::Byte(value) => Ok(Self::Byte(value)),
2631			other => Err(other),
2632		}
2633	}
2634}
2635/// [`Long`] datatype variants.
2636#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2637pub enum LongDatatype {
2638	Long,
2639	Int(IntDatatype),
2640}
2641impl LongDatatype {
2642	pub fn from_iri(iri: &Iri) -> Option<Self> {
2643		if iri == XSD_LONG {
2644			return Some(Self::Long);
2645		}
2646		if let Some(t) = IntDatatype::from_iri(iri) {
2647			return Some(Self::Int(t));
2648		}
2649		None
2650	}
2651	pub fn iri(&self) -> &'static Iri {
2652		match self {
2653			Self::Long => XSD_LONG,
2654			Self::Int(t) => t.iri(),
2655		}
2656	}
2657	pub fn parse(&self, value: &str) -> Result<LongValue, ParseError> {
2658		match self {
2659			Self::Long => ParseXsd::parse_xsd(value)
2660				.map(LongValue::Long)
2661				.map_err(|_| ParseError),
2662			Self::Int(t) => t.parse(value).map(Into::into),
2663		}
2664	}
2665}
2666impl From<IntDatatype> for LongDatatype {
2667	fn from(value: IntDatatype) -> Self {
2668		Self::Int(value)
2669	}
2670}
2671impl From<ShortDatatype> for LongDatatype {
2672	fn from(value: ShortDatatype) -> Self {
2673		Self::Int(IntDatatype::Short(value))
2674	}
2675}
2676impl TryFrom<LongDatatype> for IntDatatype {
2677	type Error = LongDatatype;
2678	fn try_from(value: LongDatatype) -> Result<Self, LongDatatype> {
2679		match value {
2680			LongDatatype::Int(value) => Ok(value),
2681			other => Err(other),
2682		}
2683	}
2684}
2685impl TryFrom<LongDatatype> for ShortDatatype {
2686	type Error = LongDatatype;
2687	fn try_from(value: LongDatatype) -> Result<Self, LongDatatype> {
2688		match value {
2689			LongDatatype::Int(IntDatatype::Short(value)) => Ok(value),
2690			other => Err(other),
2691		}
2692	}
2693}
2694/// Any specialized [`Integer`] value reference.
2695#[derive(Debug, Clone, Copy)]
2696pub enum IntegerValueRef<'a> {
2697	Integer(&'a Integer),
2698	NonPositiveInteger(&'a NonPositiveInteger),
2699	NegativeInteger(&'a NegativeInteger),
2700	NonNegativeInteger(&'a NonNegativeInteger),
2701	PositiveInteger(&'a PositiveInteger),
2702	UnsignedLong(UnsignedLong),
2703	UnsignedInt(UnsignedInt),
2704	UnsignedShort(UnsignedShort),
2705	UnsignedByte(UnsignedByte),
2706	Long(Long),
2707	Int(Int),
2708	Short(Short),
2709	Byte(Byte),
2710}
2711impl IntegerValue {
2712	pub fn as_ref(&self) -> IntegerValueRef {
2713		match self {
2714			Self::Integer(value) => IntegerValueRef::Integer(value),
2715			Self::NonPositiveInteger(value) => IntegerValueRef::NonPositiveInteger(value),
2716			Self::NegativeInteger(value) => IntegerValueRef::NegativeInteger(value),
2717			Self::NonNegativeInteger(value) => IntegerValueRef::NonNegativeInteger(value),
2718			Self::PositiveInteger(value) => IntegerValueRef::PositiveInteger(value),
2719			Self::UnsignedLong(value) => IntegerValueRef::UnsignedLong(*value),
2720			Self::UnsignedInt(value) => IntegerValueRef::UnsignedInt(*value),
2721			Self::UnsignedShort(value) => IntegerValueRef::UnsignedShort(*value),
2722			Self::UnsignedByte(value) => IntegerValueRef::UnsignedByte(*value),
2723			Self::Long(value) => IntegerValueRef::Long(*value),
2724			Self::Int(value) => IntegerValueRef::Int(*value),
2725			Self::Short(value) => IntegerValueRef::Short(*value),
2726			Self::Byte(value) => IntegerValueRef::Byte(*value),
2727		}
2728	}
2729}
2730impl<'a> IntegerValueRef<'a> {
2731	pub fn datatype(&self) -> IntegerDatatype {
2732		match self {
2733			Self::Integer(_) => IntegerDatatype::Integer,
2734			Self::NonPositiveInteger(_) => {
2735				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NonPositiveInteger)
2736			}
2737			Self::NegativeInteger(_) => {
2738				IntegerDatatype::NonPositiveInteger(NonPositiveIntegerDatatype::NegativeInteger)
2739			}
2740			Self::NonNegativeInteger(_) => {
2741				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::NonNegativeInteger)
2742			}
2743			Self::PositiveInteger(_) => {
2744				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::PositiveInteger)
2745			}
2746			Self::UnsignedLong(_) => IntegerDatatype::NonNegativeInteger(
2747				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedLong),
2748			),
2749			Self::UnsignedInt(_) => {
2750				IntegerDatatype::NonNegativeInteger(NonNegativeIntegerDatatype::UnsignedLong(
2751					UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt),
2752				))
2753			}
2754			Self::UnsignedShort(_) => IntegerDatatype::NonNegativeInteger(
2755				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2756					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
2757				)),
2758			),
2759			Self::UnsignedByte(_) => IntegerDatatype::NonNegativeInteger(
2760				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2761					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
2762				)),
2763			),
2764			Self::Long(_) => IntegerDatatype::Long(LongDatatype::Long),
2765			Self::Int(_) => IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Int)),
2766			Self::Short(_) => {
2767				IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Short(ShortDatatype::Short)))
2768			}
2769			Self::Byte(_) => {
2770				IntegerDatatype::Long(LongDatatype::Int(IntDatatype::Short(ShortDatatype::Byte)))
2771			}
2772		}
2773	}
2774	pub fn cloned(&self) -> IntegerValue {
2775		match *self {
2776			Self::Integer(value) => IntegerValue::Integer(value.to_owned()),
2777			Self::NonPositiveInteger(value) => IntegerValue::NonPositiveInteger(value.to_owned()),
2778			Self::NegativeInteger(value) => IntegerValue::NegativeInteger(value.to_owned()),
2779			Self::NonNegativeInteger(value) => IntegerValue::NonNegativeInteger(value.to_owned()),
2780			Self::PositiveInteger(value) => IntegerValue::PositiveInteger(value.to_owned()),
2781			Self::UnsignedLong(value) => IntegerValue::UnsignedLong(value),
2782			Self::UnsignedInt(value) => IntegerValue::UnsignedInt(value),
2783			Self::UnsignedShort(value) => IntegerValue::UnsignedShort(value),
2784			Self::UnsignedByte(value) => IntegerValue::UnsignedByte(value),
2785			Self::Long(value) => IntegerValue::Long(value),
2786			Self::Int(value) => IntegerValue::Int(value),
2787			Self::Short(value) => IntegerValue::Short(value),
2788			Self::Byte(value) => IntegerValue::Byte(value),
2789		}
2790	}
2791}
2792impl<'a> XsdValue for IntegerValueRef<'a> {
2793	fn datatype(&self) -> Datatype {
2794		self.datatype().into()
2795	}
2796}
2797impl<'a> fmt::Display for IntegerValueRef<'a> {
2798	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2799		match self {
2800			Self::Integer(v) => v.fmt(f),
2801			Self::NonPositiveInteger(v) => v.fmt(f),
2802			Self::NegativeInteger(v) => v.fmt(f),
2803			Self::NonNegativeInteger(v) => v.fmt(f),
2804			Self::PositiveInteger(v) => v.fmt(f),
2805			Self::UnsignedLong(v) => v.fmt(f),
2806			Self::UnsignedInt(v) => v.fmt(f),
2807			Self::UnsignedShort(v) => v.fmt(f),
2808			Self::UnsignedByte(v) => v.fmt(f),
2809			Self::Long(v) => v.fmt(f),
2810			Self::Int(v) => v.fmt(f),
2811			Self::Short(v) => v.fmt(f),
2812			Self::Byte(v) => v.fmt(f),
2813		}
2814	}
2815}
2816impl<'a> From<NonPositiveIntegerValueRef<'a>> for IntegerValueRef<'a> {
2817	fn from(value: NonPositiveIntegerValueRef<'a>) -> Self {
2818		match value {
2819			NonPositiveIntegerValueRef::NonPositiveInteger(value) => {
2820				Self::NonPositiveInteger(value)
2821			}
2822			NonPositiveIntegerValueRef::NegativeInteger(value) => Self::NegativeInteger(value),
2823		}
2824	}
2825}
2826impl<'a> TryFrom<IntegerValueRef<'a>> for NonPositiveIntegerValueRef<'a> {
2827	type Error = IntegerValueRef<'a>;
2828	fn try_from(value: IntegerValueRef<'a>) -> Result<Self, IntegerValueRef<'a>> {
2829		match value {
2830			IntegerValueRef::NonPositiveInteger(value) => Ok(Self::NonPositiveInteger(value)),
2831			IntegerValueRef::NegativeInteger(value) => Ok(Self::NegativeInteger(value)),
2832			other => Err(other),
2833		}
2834	}
2835}
2836impl<'a> From<NonNegativeIntegerValueRef<'a>> for IntegerValueRef<'a> {
2837	fn from(value: NonNegativeIntegerValueRef<'a>) -> Self {
2838		match value {
2839			NonNegativeIntegerValueRef::NonNegativeInteger(value) => {
2840				Self::NonNegativeInteger(value)
2841			}
2842			NonNegativeIntegerValueRef::PositiveInteger(value) => Self::PositiveInteger(value),
2843			NonNegativeIntegerValueRef::UnsignedLong(value) => Self::UnsignedLong(value),
2844			NonNegativeIntegerValueRef::UnsignedInt(value) => Self::UnsignedInt(value),
2845			NonNegativeIntegerValueRef::UnsignedShort(value) => Self::UnsignedShort(value),
2846			NonNegativeIntegerValueRef::UnsignedByte(value) => Self::UnsignedByte(value),
2847		}
2848	}
2849}
2850impl<'a> TryFrom<IntegerValueRef<'a>> for NonNegativeIntegerValueRef<'a> {
2851	type Error = IntegerValueRef<'a>;
2852	fn try_from(value: IntegerValueRef<'a>) -> Result<Self, IntegerValueRef<'a>> {
2853		match value {
2854			IntegerValueRef::NonNegativeInteger(value) => Ok(Self::NonNegativeInteger(value)),
2855			IntegerValueRef::PositiveInteger(value) => Ok(Self::PositiveInteger(value)),
2856			IntegerValueRef::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
2857			IntegerValueRef::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
2858			IntegerValueRef::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
2859			IntegerValueRef::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
2860			other => Err(other),
2861		}
2862	}
2863}
2864/// Any specialized [`NonPositiveInteger`] value.
2865#[derive(Debug, Clone)]
2866pub enum NonPositiveIntegerValue {
2867	NonPositiveInteger(NonPositiveInteger),
2868	NegativeInteger(NegativeInteger),
2869}
2870impl NonPositiveIntegerValue {
2871	pub fn datatype(&self) -> NonPositiveIntegerDatatype {
2872		match self {
2873			Self::NonPositiveInteger(_) => NonPositiveIntegerDatatype::NonPositiveInteger,
2874			Self::NegativeInteger(_) => NonPositiveIntegerDatatype::NegativeInteger,
2875		}
2876	}
2877}
2878impl XsdValue for NonPositiveIntegerValue {
2879	fn datatype(&self) -> Datatype {
2880		self.datatype().into()
2881	}
2882}
2883impl fmt::Display for NonPositiveIntegerValue {
2884	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2885		match self {
2886			Self::NonPositiveInteger(v) => v.fmt(f),
2887			Self::NegativeInteger(v) => v.fmt(f),
2888		}
2889	}
2890}
2891/// Any specialized [`NonPositiveInteger`] value reference.
2892#[derive(Debug, Clone, Copy)]
2893pub enum NonPositiveIntegerValueRef<'a> {
2894	NonPositiveInteger(&'a NonPositiveInteger),
2895	NegativeInteger(&'a NegativeInteger),
2896}
2897impl NonPositiveIntegerValue {
2898	pub fn as_ref(&self) -> NonPositiveIntegerValueRef {
2899		match self {
2900			Self::NonPositiveInteger(value) => {
2901				NonPositiveIntegerValueRef::NonPositiveInteger(value)
2902			}
2903			Self::NegativeInteger(value) => NonPositiveIntegerValueRef::NegativeInteger(value),
2904		}
2905	}
2906}
2907impl<'a> NonPositiveIntegerValueRef<'a> {
2908	pub fn datatype(&self) -> NonPositiveIntegerDatatype {
2909		match self {
2910			Self::NonPositiveInteger(_) => NonPositiveIntegerDatatype::NonPositiveInteger,
2911			Self::NegativeInteger(_) => NonPositiveIntegerDatatype::NegativeInteger,
2912		}
2913	}
2914	pub fn cloned(&self) -> NonPositiveIntegerValue {
2915		match *self {
2916			Self::NonPositiveInteger(value) => {
2917				NonPositiveIntegerValue::NonPositiveInteger(value.to_owned())
2918			}
2919			Self::NegativeInteger(value) => {
2920				NonPositiveIntegerValue::NegativeInteger(value.to_owned())
2921			}
2922		}
2923	}
2924}
2925impl<'a> XsdValue for NonPositiveIntegerValueRef<'a> {
2926	fn datatype(&self) -> Datatype {
2927		self.datatype().into()
2928	}
2929}
2930impl<'a> fmt::Display for NonPositiveIntegerValueRef<'a> {
2931	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2932		match self {
2933			Self::NonPositiveInteger(v) => v.fmt(f),
2934			Self::NegativeInteger(v) => v.fmt(f),
2935		}
2936	}
2937}
2938/// Any specialized [`NonNegativeInteger`] value.
2939#[derive(Debug, Clone)]
2940pub enum NonNegativeIntegerValue {
2941	NonNegativeInteger(NonNegativeInteger),
2942	PositiveInteger(PositiveInteger),
2943	UnsignedLong(UnsignedLong),
2944	UnsignedInt(UnsignedInt),
2945	UnsignedShort(UnsignedShort),
2946	UnsignedByte(UnsignedByte),
2947}
2948impl NonNegativeIntegerValue {
2949	pub fn datatype(&self) -> NonNegativeIntegerDatatype {
2950		match self {
2951			Self::NonNegativeInteger(_) => NonNegativeIntegerDatatype::NonNegativeInteger,
2952			Self::PositiveInteger(_) => NonNegativeIntegerDatatype::PositiveInteger,
2953			Self::UnsignedLong(_) => {
2954				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedLong)
2955			}
2956			Self::UnsignedInt(_) => NonNegativeIntegerDatatype::UnsignedLong(
2957				UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt),
2958			),
2959			Self::UnsignedShort(_) => {
2960				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2961					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
2962				))
2963			}
2964			Self::UnsignedByte(_) => {
2965				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
2966					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
2967				))
2968			}
2969		}
2970	}
2971}
2972impl XsdValue for NonNegativeIntegerValue {
2973	fn datatype(&self) -> Datatype {
2974		self.datatype().into()
2975	}
2976}
2977impl fmt::Display for NonNegativeIntegerValue {
2978	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2979		match self {
2980			Self::NonNegativeInteger(v) => v.fmt(f),
2981			Self::PositiveInteger(v) => v.fmt(f),
2982			Self::UnsignedLong(v) => v.fmt(f),
2983			Self::UnsignedInt(v) => v.fmt(f),
2984			Self::UnsignedShort(v) => v.fmt(f),
2985			Self::UnsignedByte(v) => v.fmt(f),
2986		}
2987	}
2988}
2989impl From<UnsignedLongValue> for NonNegativeIntegerValue {
2990	fn from(value: UnsignedLongValue) -> Self {
2991		match value {
2992			UnsignedLongValue::UnsignedLong(value) => Self::UnsignedLong(value),
2993			UnsignedLongValue::UnsignedInt(value) => Self::UnsignedInt(value),
2994			UnsignedLongValue::UnsignedShort(value) => Self::UnsignedShort(value),
2995			UnsignedLongValue::UnsignedByte(value) => Self::UnsignedByte(value),
2996		}
2997	}
2998}
2999impl From<UnsignedIntValue> for NonNegativeIntegerValue {
3000	fn from(value: UnsignedIntValue) -> Self {
3001		match value {
3002			UnsignedIntValue::UnsignedInt(value) => Self::UnsignedInt(value),
3003			UnsignedIntValue::UnsignedShort(value) => Self::UnsignedShort(value),
3004			UnsignedIntValue::UnsignedByte(value) => Self::UnsignedByte(value),
3005		}
3006	}
3007}
3008impl From<UnsignedShortValue> for NonNegativeIntegerValue {
3009	fn from(value: UnsignedShortValue) -> Self {
3010		match value {
3011			UnsignedShortValue::UnsignedShort(value) => Self::UnsignedShort(value),
3012			UnsignedShortValue::UnsignedByte(value) => Self::UnsignedByte(value),
3013		}
3014	}
3015}
3016impl TryFrom<NonNegativeIntegerValue> for UnsignedLongValue {
3017	type Error = NonNegativeIntegerValue;
3018	fn try_from(value: NonNegativeIntegerValue) -> Result<Self, NonNegativeIntegerValue> {
3019		match value {
3020			NonNegativeIntegerValue::UnsignedLong(value) => Ok(Self::UnsignedLong(value)),
3021			NonNegativeIntegerValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
3022			NonNegativeIntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
3023			NonNegativeIntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
3024			other => Err(other),
3025		}
3026	}
3027}
3028impl TryFrom<NonNegativeIntegerValue> for UnsignedIntValue {
3029	type Error = NonNegativeIntegerValue;
3030	fn try_from(value: NonNegativeIntegerValue) -> Result<Self, NonNegativeIntegerValue> {
3031		match value {
3032			NonNegativeIntegerValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
3033			NonNegativeIntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
3034			NonNegativeIntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
3035			other => Err(other),
3036		}
3037	}
3038}
3039impl TryFrom<NonNegativeIntegerValue> for UnsignedShortValue {
3040	type Error = NonNegativeIntegerValue;
3041	fn try_from(value: NonNegativeIntegerValue) -> Result<Self, NonNegativeIntegerValue> {
3042		match value {
3043			NonNegativeIntegerValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
3044			NonNegativeIntegerValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
3045			other => Err(other),
3046		}
3047	}
3048}
3049/// [`UnsignedLong`] datatype variants.
3050#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3051pub enum UnsignedLongDatatype {
3052	UnsignedLong,
3053	UnsignedInt(UnsignedIntDatatype),
3054}
3055impl UnsignedLongDatatype {
3056	pub fn from_iri(iri: &Iri) -> Option<Self> {
3057		if iri == XSD_UNSIGNED_LONG {
3058			return Some(Self::UnsignedLong);
3059		}
3060		if let Some(t) = UnsignedIntDatatype::from_iri(iri) {
3061			return Some(Self::UnsignedInt(t));
3062		}
3063		None
3064	}
3065	pub fn iri(&self) -> &'static Iri {
3066		match self {
3067			Self::UnsignedLong => XSD_UNSIGNED_LONG,
3068			Self::UnsignedInt(t) => t.iri(),
3069		}
3070	}
3071	pub fn parse(&self, value: &str) -> Result<UnsignedLongValue, ParseError> {
3072		match self {
3073			Self::UnsignedLong => ParseXsd::parse_xsd(value)
3074				.map(UnsignedLongValue::UnsignedLong)
3075				.map_err(|_| ParseError),
3076			Self::UnsignedInt(t) => t.parse(value).map(Into::into),
3077		}
3078	}
3079}
3080impl From<UnsignedIntDatatype> for UnsignedLongDatatype {
3081	fn from(value: UnsignedIntDatatype) -> Self {
3082		Self::UnsignedInt(value)
3083	}
3084}
3085impl From<UnsignedShortDatatype> for UnsignedLongDatatype {
3086	fn from(value: UnsignedShortDatatype) -> Self {
3087		Self::UnsignedInt(UnsignedIntDatatype::UnsignedShort(value))
3088	}
3089}
3090impl TryFrom<UnsignedLongDatatype> for UnsignedIntDatatype {
3091	type Error = UnsignedLongDatatype;
3092	fn try_from(value: UnsignedLongDatatype) -> Result<Self, UnsignedLongDatatype> {
3093		match value {
3094			UnsignedLongDatatype::UnsignedInt(value) => Ok(value),
3095			other => Err(other),
3096		}
3097	}
3098}
3099impl TryFrom<UnsignedLongDatatype> for UnsignedShortDatatype {
3100	type Error = UnsignedLongDatatype;
3101	fn try_from(value: UnsignedLongDatatype) -> Result<Self, UnsignedLongDatatype> {
3102		match value {
3103			UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedShort(value)) => {
3104				Ok(value)
3105			}
3106			other => Err(other),
3107		}
3108	}
3109}
3110/// Any specialized [`NonNegativeInteger`] value reference.
3111#[derive(Debug, Clone, Copy)]
3112pub enum NonNegativeIntegerValueRef<'a> {
3113	NonNegativeInteger(&'a NonNegativeInteger),
3114	PositiveInteger(&'a PositiveInteger),
3115	UnsignedLong(UnsignedLong),
3116	UnsignedInt(UnsignedInt),
3117	UnsignedShort(UnsignedShort),
3118	UnsignedByte(UnsignedByte),
3119}
3120impl NonNegativeIntegerValue {
3121	pub fn as_ref(&self) -> NonNegativeIntegerValueRef {
3122		match self {
3123			Self::NonNegativeInteger(value) => {
3124				NonNegativeIntegerValueRef::NonNegativeInteger(value)
3125			}
3126			Self::PositiveInteger(value) => NonNegativeIntegerValueRef::PositiveInteger(value),
3127			Self::UnsignedLong(value) => NonNegativeIntegerValueRef::UnsignedLong(*value),
3128			Self::UnsignedInt(value) => NonNegativeIntegerValueRef::UnsignedInt(*value),
3129			Self::UnsignedShort(value) => NonNegativeIntegerValueRef::UnsignedShort(*value),
3130			Self::UnsignedByte(value) => NonNegativeIntegerValueRef::UnsignedByte(*value),
3131		}
3132	}
3133}
3134impl<'a> NonNegativeIntegerValueRef<'a> {
3135	pub fn datatype(&self) -> NonNegativeIntegerDatatype {
3136		match self {
3137			Self::NonNegativeInteger(_) => NonNegativeIntegerDatatype::NonNegativeInteger,
3138			Self::PositiveInteger(_) => NonNegativeIntegerDatatype::PositiveInteger,
3139			Self::UnsignedLong(_) => {
3140				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedLong)
3141			}
3142			Self::UnsignedInt(_) => NonNegativeIntegerDatatype::UnsignedLong(
3143				UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt),
3144			),
3145			Self::UnsignedShort(_) => {
3146				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
3147					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
3148				))
3149			}
3150			Self::UnsignedByte(_) => {
3151				NonNegativeIntegerDatatype::UnsignedLong(UnsignedLongDatatype::UnsignedInt(
3152					UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
3153				))
3154			}
3155		}
3156	}
3157	pub fn cloned(&self) -> NonNegativeIntegerValue {
3158		match *self {
3159			Self::NonNegativeInteger(value) => {
3160				NonNegativeIntegerValue::NonNegativeInteger(value.to_owned())
3161			}
3162			Self::PositiveInteger(value) => {
3163				NonNegativeIntegerValue::PositiveInteger(value.to_owned())
3164			}
3165			Self::UnsignedLong(value) => NonNegativeIntegerValue::UnsignedLong(value),
3166			Self::UnsignedInt(value) => NonNegativeIntegerValue::UnsignedInt(value),
3167			Self::UnsignedShort(value) => NonNegativeIntegerValue::UnsignedShort(value),
3168			Self::UnsignedByte(value) => NonNegativeIntegerValue::UnsignedByte(value),
3169		}
3170	}
3171}
3172impl<'a> XsdValue for NonNegativeIntegerValueRef<'a> {
3173	fn datatype(&self) -> Datatype {
3174		self.datatype().into()
3175	}
3176}
3177impl<'a> fmt::Display for NonNegativeIntegerValueRef<'a> {
3178	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3179		match self {
3180			Self::NonNegativeInteger(v) => v.fmt(f),
3181			Self::PositiveInteger(v) => v.fmt(f),
3182			Self::UnsignedLong(v) => v.fmt(f),
3183			Self::UnsignedInt(v) => v.fmt(f),
3184			Self::UnsignedShort(v) => v.fmt(f),
3185			Self::UnsignedByte(v) => v.fmt(f),
3186		}
3187	}
3188}
3189/// Any specialized [`UnsignedLong`] value.
3190#[derive(Debug, Clone)]
3191pub enum UnsignedLongValue {
3192	UnsignedLong(UnsignedLong),
3193	UnsignedInt(UnsignedInt),
3194	UnsignedShort(UnsignedShort),
3195	UnsignedByte(UnsignedByte),
3196}
3197impl UnsignedLongValue {
3198	pub fn datatype(&self) -> UnsignedLongDatatype {
3199		match self {
3200			Self::UnsignedLong(_) => UnsignedLongDatatype::UnsignedLong,
3201			Self::UnsignedInt(_) => {
3202				UnsignedLongDatatype::UnsignedInt(UnsignedIntDatatype::UnsignedInt)
3203			}
3204			Self::UnsignedShort(_) => UnsignedLongDatatype::UnsignedInt(
3205				UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort),
3206			),
3207			Self::UnsignedByte(_) => UnsignedLongDatatype::UnsignedInt(
3208				UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte),
3209			),
3210		}
3211	}
3212}
3213impl XsdValue for UnsignedLongValue {
3214	fn datatype(&self) -> Datatype {
3215		self.datatype().into()
3216	}
3217}
3218impl fmt::Display for UnsignedLongValue {
3219	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3220		match self {
3221			Self::UnsignedLong(v) => v.fmt(f),
3222			Self::UnsignedInt(v) => v.fmt(f),
3223			Self::UnsignedShort(v) => v.fmt(f),
3224			Self::UnsignedByte(v) => v.fmt(f),
3225		}
3226	}
3227}
3228impl From<UnsignedIntValue> for UnsignedLongValue {
3229	fn from(value: UnsignedIntValue) -> Self {
3230		match value {
3231			UnsignedIntValue::UnsignedInt(value) => Self::UnsignedInt(value),
3232			UnsignedIntValue::UnsignedShort(value) => Self::UnsignedShort(value),
3233			UnsignedIntValue::UnsignedByte(value) => Self::UnsignedByte(value),
3234		}
3235	}
3236}
3237impl From<UnsignedShortValue> for UnsignedLongValue {
3238	fn from(value: UnsignedShortValue) -> Self {
3239		match value {
3240			UnsignedShortValue::UnsignedShort(value) => Self::UnsignedShort(value),
3241			UnsignedShortValue::UnsignedByte(value) => Self::UnsignedByte(value),
3242		}
3243	}
3244}
3245impl TryFrom<UnsignedLongValue> for UnsignedIntValue {
3246	type Error = UnsignedLongValue;
3247	fn try_from(value: UnsignedLongValue) -> Result<Self, UnsignedLongValue> {
3248		match value {
3249			UnsignedLongValue::UnsignedInt(value) => Ok(Self::UnsignedInt(value)),
3250			UnsignedLongValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
3251			UnsignedLongValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
3252			other => Err(other),
3253		}
3254	}
3255}
3256impl TryFrom<UnsignedLongValue> for UnsignedShortValue {
3257	type Error = UnsignedLongValue;
3258	fn try_from(value: UnsignedLongValue) -> Result<Self, UnsignedLongValue> {
3259		match value {
3260			UnsignedLongValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
3261			UnsignedLongValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
3262			other => Err(other),
3263		}
3264	}
3265}
3266/// [`UnsignedInt`] datatype variants.
3267#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3268pub enum UnsignedIntDatatype {
3269	UnsignedInt,
3270	UnsignedShort(UnsignedShortDatatype),
3271}
3272impl UnsignedIntDatatype {
3273	pub fn from_iri(iri: &Iri) -> Option<Self> {
3274		if iri == XSD_UNSIGNED_INT {
3275			return Some(Self::UnsignedInt);
3276		}
3277		if let Some(t) = UnsignedShortDatatype::from_iri(iri) {
3278			return Some(Self::UnsignedShort(t));
3279		}
3280		None
3281	}
3282	pub fn iri(&self) -> &'static Iri {
3283		match self {
3284			Self::UnsignedInt => XSD_UNSIGNED_INT,
3285			Self::UnsignedShort(t) => t.iri(),
3286		}
3287	}
3288	pub fn parse(&self, value: &str) -> Result<UnsignedIntValue, ParseError> {
3289		match self {
3290			Self::UnsignedInt => ParseXsd::parse_xsd(value)
3291				.map(UnsignedIntValue::UnsignedInt)
3292				.map_err(|_| ParseError),
3293			Self::UnsignedShort(t) => t.parse(value).map(Into::into),
3294		}
3295	}
3296}
3297impl From<UnsignedShortDatatype> for UnsignedIntDatatype {
3298	fn from(value: UnsignedShortDatatype) -> Self {
3299		Self::UnsignedShort(value)
3300	}
3301}
3302impl TryFrom<UnsignedIntDatatype> for UnsignedShortDatatype {
3303	type Error = UnsignedIntDatatype;
3304	fn try_from(value: UnsignedIntDatatype) -> Result<Self, UnsignedIntDatatype> {
3305		match value {
3306			UnsignedIntDatatype::UnsignedShort(value) => Ok(value),
3307			other => Err(other),
3308		}
3309	}
3310}
3311/// Any specialized [`UnsignedInt`] value.
3312#[derive(Debug, Clone)]
3313pub enum UnsignedIntValue {
3314	UnsignedInt(UnsignedInt),
3315	UnsignedShort(UnsignedShort),
3316	UnsignedByte(UnsignedByte),
3317}
3318impl UnsignedIntValue {
3319	pub fn datatype(&self) -> UnsignedIntDatatype {
3320		match self {
3321			Self::UnsignedInt(_) => UnsignedIntDatatype::UnsignedInt,
3322			Self::UnsignedShort(_) => {
3323				UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedShort)
3324			}
3325			Self::UnsignedByte(_) => {
3326				UnsignedIntDatatype::UnsignedShort(UnsignedShortDatatype::UnsignedByte)
3327			}
3328		}
3329	}
3330}
3331impl XsdValue for UnsignedIntValue {
3332	fn datatype(&self) -> Datatype {
3333		self.datatype().into()
3334	}
3335}
3336impl fmt::Display for UnsignedIntValue {
3337	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3338		match self {
3339			Self::UnsignedInt(v) => v.fmt(f),
3340			Self::UnsignedShort(v) => v.fmt(f),
3341			Self::UnsignedByte(v) => v.fmt(f),
3342		}
3343	}
3344}
3345impl From<UnsignedShortValue> for UnsignedIntValue {
3346	fn from(value: UnsignedShortValue) -> Self {
3347		match value {
3348			UnsignedShortValue::UnsignedShort(value) => Self::UnsignedShort(value),
3349			UnsignedShortValue::UnsignedByte(value) => Self::UnsignedByte(value),
3350		}
3351	}
3352}
3353impl TryFrom<UnsignedIntValue> for UnsignedShortValue {
3354	type Error = UnsignedIntValue;
3355	fn try_from(value: UnsignedIntValue) -> Result<Self, UnsignedIntValue> {
3356		match value {
3357			UnsignedIntValue::UnsignedShort(value) => Ok(Self::UnsignedShort(value)),
3358			UnsignedIntValue::UnsignedByte(value) => Ok(Self::UnsignedByte(value)),
3359			other => Err(other),
3360		}
3361	}
3362}
3363/// [`UnsignedShort`] datatype variants.
3364#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3365pub enum UnsignedShortDatatype {
3366	UnsignedShort,
3367	UnsignedByte,
3368}
3369impl UnsignedShortDatatype {
3370	pub fn from_iri(iri: &Iri) -> Option<Self> {
3371		if iri == XSD_UNSIGNED_SHORT {
3372			return Some(Self::UnsignedShort);
3373		}
3374		if iri == XSD_UNSIGNED_BYTE {
3375			return Some(Self::UnsignedByte);
3376		}
3377		None
3378	}
3379	pub fn iri(&self) -> &'static Iri {
3380		match self {
3381			Self::UnsignedShort => XSD_UNSIGNED_SHORT,
3382			Self::UnsignedByte => XSD_UNSIGNED_BYTE,
3383		}
3384	}
3385	pub fn parse(&self, value: &str) -> Result<UnsignedShortValue, ParseError> {
3386		match self {
3387			Self::UnsignedShort => ParseXsd::parse_xsd(value)
3388				.map(UnsignedShortValue::UnsignedShort)
3389				.map_err(|_| ParseError),
3390			Self::UnsignedByte => ParseXsd::parse_xsd(value)
3391				.map(UnsignedShortValue::UnsignedByte)
3392				.map_err(|_| ParseError),
3393		}
3394	}
3395}
3396/// Any specialized [`UnsignedShort`] value.
3397#[derive(Debug, Clone)]
3398pub enum UnsignedShortValue {
3399	UnsignedShort(UnsignedShort),
3400	UnsignedByte(UnsignedByte),
3401}
3402impl UnsignedShortValue {
3403	pub fn datatype(&self) -> UnsignedShortDatatype {
3404		match self {
3405			Self::UnsignedShort(_) => UnsignedShortDatatype::UnsignedShort,
3406			Self::UnsignedByte(_) => UnsignedShortDatatype::UnsignedByte,
3407		}
3408	}
3409}
3410impl XsdValue for UnsignedShortValue {
3411	fn datatype(&self) -> Datatype {
3412		self.datatype().into()
3413	}
3414}
3415impl fmt::Display for UnsignedShortValue {
3416	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3417		match self {
3418			Self::UnsignedShort(v) => v.fmt(f),
3419			Self::UnsignedByte(v) => v.fmt(f),
3420		}
3421	}
3422}
3423/// Any specialized [`Long`] value.
3424#[derive(Debug, Clone)]
3425pub enum LongValue {
3426	Long(Long),
3427	Int(Int),
3428	Short(Short),
3429	Byte(Byte),
3430}
3431impl LongValue {
3432	pub fn datatype(&self) -> LongDatatype {
3433		match self {
3434			Self::Long(_) => LongDatatype::Long,
3435			Self::Int(_) => LongDatatype::Int(IntDatatype::Int),
3436			Self::Short(_) => LongDatatype::Int(IntDatatype::Short(ShortDatatype::Short)),
3437			Self::Byte(_) => LongDatatype::Int(IntDatatype::Short(ShortDatatype::Byte)),
3438		}
3439	}
3440}
3441impl XsdValue for LongValue {
3442	fn datatype(&self) -> Datatype {
3443		self.datatype().into()
3444	}
3445}
3446impl fmt::Display for LongValue {
3447	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3448		match self {
3449			Self::Long(v) => v.fmt(f),
3450			Self::Int(v) => v.fmt(f),
3451			Self::Short(v) => v.fmt(f),
3452			Self::Byte(v) => v.fmt(f),
3453		}
3454	}
3455}
3456impl From<IntValue> for LongValue {
3457	fn from(value: IntValue) -> Self {
3458		match value {
3459			IntValue::Int(value) => Self::Int(value),
3460			IntValue::Short(value) => Self::Short(value),
3461			IntValue::Byte(value) => Self::Byte(value),
3462		}
3463	}
3464}
3465impl From<ShortValue> for LongValue {
3466	fn from(value: ShortValue) -> Self {
3467		match value {
3468			ShortValue::Short(value) => Self::Short(value),
3469			ShortValue::Byte(value) => Self::Byte(value),
3470		}
3471	}
3472}
3473impl TryFrom<LongValue> for IntValue {
3474	type Error = LongValue;
3475	fn try_from(value: LongValue) -> Result<Self, LongValue> {
3476		match value {
3477			LongValue::Int(value) => Ok(Self::Int(value)),
3478			LongValue::Short(value) => Ok(Self::Short(value)),
3479			LongValue::Byte(value) => Ok(Self::Byte(value)),
3480			other => Err(other),
3481		}
3482	}
3483}
3484impl TryFrom<LongValue> for ShortValue {
3485	type Error = LongValue;
3486	fn try_from(value: LongValue) -> Result<Self, LongValue> {
3487		match value {
3488			LongValue::Short(value) => Ok(Self::Short(value)),
3489			LongValue::Byte(value) => Ok(Self::Byte(value)),
3490			other => Err(other),
3491		}
3492	}
3493}
3494/// [`Int`] datatype variants.
3495#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3496pub enum IntDatatype {
3497	Int,
3498	Short(ShortDatatype),
3499}
3500impl IntDatatype {
3501	pub fn from_iri(iri: &Iri) -> Option<Self> {
3502		if iri == XSD_INT {
3503			return Some(Self::Int);
3504		}
3505		if let Some(t) = ShortDatatype::from_iri(iri) {
3506			return Some(Self::Short(t));
3507		}
3508		None
3509	}
3510	pub fn iri(&self) -> &'static Iri {
3511		match self {
3512			Self::Int => XSD_INT,
3513			Self::Short(t) => t.iri(),
3514		}
3515	}
3516	pub fn parse(&self, value: &str) -> Result<IntValue, ParseError> {
3517		match self {
3518			Self::Int => ParseXsd::parse_xsd(value)
3519				.map(IntValue::Int)
3520				.map_err(|_| ParseError),
3521			Self::Short(t) => t.parse(value).map(Into::into),
3522		}
3523	}
3524}
3525impl From<ShortDatatype> for IntDatatype {
3526	fn from(value: ShortDatatype) -> Self {
3527		Self::Short(value)
3528	}
3529}
3530impl TryFrom<IntDatatype> for ShortDatatype {
3531	type Error = IntDatatype;
3532	fn try_from(value: IntDatatype) -> Result<Self, IntDatatype> {
3533		match value {
3534			IntDatatype::Short(value) => Ok(value),
3535			other => Err(other),
3536		}
3537	}
3538}
3539/// Any specialized [`Int`] value.
3540#[derive(Debug, Clone)]
3541pub enum IntValue {
3542	Int(Int),
3543	Short(Short),
3544	Byte(Byte),
3545}
3546impl IntValue {
3547	pub fn datatype(&self) -> IntDatatype {
3548		match self {
3549			Self::Int(_) => IntDatatype::Int,
3550			Self::Short(_) => IntDatatype::Short(ShortDatatype::Short),
3551			Self::Byte(_) => IntDatatype::Short(ShortDatatype::Byte),
3552		}
3553	}
3554}
3555impl XsdValue for IntValue {
3556	fn datatype(&self) -> Datatype {
3557		self.datatype().into()
3558	}
3559}
3560impl fmt::Display for IntValue {
3561	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3562		match self {
3563			Self::Int(v) => v.fmt(f),
3564			Self::Short(v) => v.fmt(f),
3565			Self::Byte(v) => v.fmt(f),
3566		}
3567	}
3568}
3569impl From<ShortValue> for IntValue {
3570	fn from(value: ShortValue) -> Self {
3571		match value {
3572			ShortValue::Short(value) => Self::Short(value),
3573			ShortValue::Byte(value) => Self::Byte(value),
3574		}
3575	}
3576}
3577impl TryFrom<IntValue> for ShortValue {
3578	type Error = IntValue;
3579	fn try_from(value: IntValue) -> Result<Self, IntValue> {
3580		match value {
3581			IntValue::Short(value) => Ok(Self::Short(value)),
3582			IntValue::Byte(value) => Ok(Self::Byte(value)),
3583			other => Err(other),
3584		}
3585	}
3586}
3587/// [`Short`] datatype variants.
3588#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
3589pub enum ShortDatatype {
3590	Short,
3591	Byte,
3592}
3593impl ShortDatatype {
3594	pub fn from_iri(iri: &Iri) -> Option<Self> {
3595		if iri == XSD_SHORT {
3596			return Some(Self::Short);
3597		}
3598		if iri == XSD_BYTE {
3599			return Some(Self::Byte);
3600		}
3601		None
3602	}
3603	pub fn iri(&self) -> &'static Iri {
3604		match self {
3605			Self::Short => XSD_SHORT,
3606			Self::Byte => XSD_BYTE,
3607		}
3608	}
3609	pub fn parse(&self, value: &str) -> Result<ShortValue, ParseError> {
3610		match self {
3611			Self::Short => ParseXsd::parse_xsd(value)
3612				.map(ShortValue::Short)
3613				.map_err(|_| ParseError),
3614			Self::Byte => ParseXsd::parse_xsd(value)
3615				.map(ShortValue::Byte)
3616				.map_err(|_| ParseError),
3617		}
3618	}
3619}
3620/// Any specialized [`Short`] value.
3621#[derive(Debug, Clone)]
3622pub enum ShortValue {
3623	Short(Short),
3624	Byte(Byte),
3625}
3626impl ShortValue {
3627	pub fn datatype(&self) -> ShortDatatype {
3628		match self {
3629			Self::Short(_) => ShortDatatype::Short,
3630			Self::Byte(_) => ShortDatatype::Byte,
3631		}
3632	}
3633}
3634impl XsdValue for ShortValue {
3635	fn datatype(&self) -> Datatype {
3636		self.datatype().into()
3637	}
3638}
3639impl fmt::Display for ShortValue {
3640	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3641		match self {
3642			Self::Short(v) => v.fmt(f),
3643			Self::Byte(v) => v.fmt(f),
3644		}
3645	}
3646}
3647impl From<StringDatatype> for Datatype {
3648	fn from(value: StringDatatype) -> Self {
3649		Self::String(value)
3650	}
3651}
3652impl From<NormalizedStringDatatype> for Datatype {
3653	fn from(value: NormalizedStringDatatype) -> Self {
3654		Self::String(StringDatatype::NormalizedString(value))
3655	}
3656}
3657impl From<TokenDatatype> for Datatype {
3658	fn from(value: TokenDatatype) -> Self {
3659		Self::String(StringDatatype::NormalizedString(
3660			NormalizedStringDatatype::Token(value),
3661		))
3662	}
3663}
3664impl From<NameDatatype> for Datatype {
3665	fn from(value: NameDatatype) -> Self {
3666		Self::String(StringDatatype::NormalizedString(
3667			NormalizedStringDatatype::Token(TokenDatatype::Name(value)),
3668		))
3669	}
3670}
3671impl From<NCNameDatatype> for Datatype {
3672	fn from(value: NCNameDatatype) -> Self {
3673		Self::String(StringDatatype::NormalizedString(
3674			NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(value))),
3675		))
3676	}
3677}
3678impl TryFrom<Datatype> for StringDatatype {
3679	type Error = Datatype;
3680	fn try_from(value: Datatype) -> Result<Self, Datatype> {
3681		match value {
3682			Datatype::String(value) => Ok(value),
3683			other => Err(other),
3684		}
3685	}
3686}
3687impl TryFrom<Datatype> for NormalizedStringDatatype {
3688	type Error = Datatype;
3689	fn try_from(value: Datatype) -> Result<Self, Datatype> {
3690		match value {
3691			Datatype::String(StringDatatype::NormalizedString(value)) => Ok(value),
3692			other => Err(other),
3693		}
3694	}
3695}
3696impl TryFrom<Datatype> for TokenDatatype {
3697	type Error = Datatype;
3698	fn try_from(value: Datatype) -> Result<Self, Datatype> {
3699		match value {
3700			Datatype::String(StringDatatype::NormalizedString(
3701				NormalizedStringDatatype::Token(value),
3702			)) => Ok(value),
3703			other => Err(other),
3704		}
3705	}
3706}
3707impl TryFrom<Datatype> for NameDatatype {
3708	type Error = Datatype;
3709	fn try_from(value: Datatype) -> Result<Self, Datatype> {
3710		match value {
3711			Datatype::String(StringDatatype::NormalizedString(
3712				NormalizedStringDatatype::Token(TokenDatatype::Name(value)),
3713			)) => Ok(value),
3714			other => Err(other),
3715		}
3716	}
3717}
3718impl TryFrom<Datatype> for NCNameDatatype {
3719	type Error = Datatype;
3720	fn try_from(value: Datatype) -> Result<Self, Datatype> {
3721		match value {
3722			Datatype::String(StringDatatype::NormalizedString(
3723				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(value))),
3724			)) => Ok(value),
3725			other => Err(other),
3726		}
3727	}
3728}
3729impl From<StringValue> for Value {
3730	fn from(value: StringValue) -> Self {
3731		match value {
3732			StringValue::String(value) => Self::String(value),
3733			StringValue::NormalizedString(value) => Self::NormalizedString(value),
3734			StringValue::Token(value) => Self::Token(value),
3735			StringValue::Language(value) => Self::Language(value),
3736			StringValue::Name(value) => Self::Name(value),
3737			StringValue::NCName(value) => Self::NCName(value),
3738			StringValue::Id(value) => Self::Id(value),
3739			StringValue::IdRef(value) => Self::IdRef(value),
3740			StringValue::NMToken(value) => Self::NMToken(value),
3741		}
3742	}
3743}
3744impl From<NormalizedStringValue> for Value {
3745	fn from(value: NormalizedStringValue) -> Self {
3746		match value {
3747			NormalizedStringValue::NormalizedString(value) => Self::NormalizedString(value),
3748			NormalizedStringValue::Token(value) => Self::Token(value),
3749			NormalizedStringValue::Language(value) => Self::Language(value),
3750			NormalizedStringValue::Name(value) => Self::Name(value),
3751			NormalizedStringValue::NCName(value) => Self::NCName(value),
3752			NormalizedStringValue::Id(value) => Self::Id(value),
3753			NormalizedStringValue::IdRef(value) => Self::IdRef(value),
3754			NormalizedStringValue::NMToken(value) => Self::NMToken(value),
3755		}
3756	}
3757}
3758impl From<TokenValue> for Value {
3759	fn from(value: TokenValue) -> Self {
3760		match value {
3761			TokenValue::Token(value) => Self::Token(value),
3762			TokenValue::Language(value) => Self::Language(value),
3763			TokenValue::Name(value) => Self::Name(value),
3764			TokenValue::NCName(value) => Self::NCName(value),
3765			TokenValue::Id(value) => Self::Id(value),
3766			TokenValue::IdRef(value) => Self::IdRef(value),
3767			TokenValue::NMToken(value) => Self::NMToken(value),
3768		}
3769	}
3770}
3771impl From<NameValue> for Value {
3772	fn from(value: NameValue) -> Self {
3773		match value {
3774			NameValue::Name(value) => Self::Name(value),
3775			NameValue::NCName(value) => Self::NCName(value),
3776			NameValue::Id(value) => Self::Id(value),
3777			NameValue::IdRef(value) => Self::IdRef(value),
3778		}
3779	}
3780}
3781impl From<NCNameValue> for Value {
3782	fn from(value: NCNameValue) -> Self {
3783		match value {
3784			NCNameValue::NCName(value) => Self::NCName(value),
3785			NCNameValue::Id(value) => Self::Id(value),
3786			NCNameValue::IdRef(value) => Self::IdRef(value),
3787		}
3788	}
3789}
3790impl TryFrom<Value> for StringValue {
3791	type Error = Value;
3792	fn try_from(value: Value) -> Result<Self, Value> {
3793		match value {
3794			Value::String(value) => Ok(Self::String(value)),
3795			Value::NormalizedString(value) => Ok(Self::NormalizedString(value)),
3796			Value::Token(value) => Ok(Self::Token(value)),
3797			Value::Language(value) => Ok(Self::Language(value)),
3798			Value::Name(value) => Ok(Self::Name(value)),
3799			Value::NCName(value) => Ok(Self::NCName(value)),
3800			Value::Id(value) => Ok(Self::Id(value)),
3801			Value::IdRef(value) => Ok(Self::IdRef(value)),
3802			Value::NMToken(value) => Ok(Self::NMToken(value)),
3803			other => Err(other),
3804		}
3805	}
3806}
3807impl TryFrom<Value> for NormalizedStringValue {
3808	type Error = Value;
3809	fn try_from(value: Value) -> Result<Self, Value> {
3810		match value {
3811			Value::NormalizedString(value) => Ok(Self::NormalizedString(value)),
3812			Value::Token(value) => Ok(Self::Token(value)),
3813			Value::Language(value) => Ok(Self::Language(value)),
3814			Value::Name(value) => Ok(Self::Name(value)),
3815			Value::NCName(value) => Ok(Self::NCName(value)),
3816			Value::Id(value) => Ok(Self::Id(value)),
3817			Value::IdRef(value) => Ok(Self::IdRef(value)),
3818			Value::NMToken(value) => Ok(Self::NMToken(value)),
3819			other => Err(other),
3820		}
3821	}
3822}
3823impl TryFrom<Value> for TokenValue {
3824	type Error = Value;
3825	fn try_from(value: Value) -> Result<Self, Value> {
3826		match value {
3827			Value::Token(value) => Ok(Self::Token(value)),
3828			Value::Language(value) => Ok(Self::Language(value)),
3829			Value::Name(value) => Ok(Self::Name(value)),
3830			Value::NCName(value) => Ok(Self::NCName(value)),
3831			Value::Id(value) => Ok(Self::Id(value)),
3832			Value::IdRef(value) => Ok(Self::IdRef(value)),
3833			Value::NMToken(value) => Ok(Self::NMToken(value)),
3834			other => Err(other),
3835		}
3836	}
3837}
3838impl TryFrom<Value> for NameValue {
3839	type Error = Value;
3840	fn try_from(value: Value) -> Result<Self, Value> {
3841		match value {
3842			Value::Name(value) => Ok(Self::Name(value)),
3843			Value::NCName(value) => Ok(Self::NCName(value)),
3844			Value::Id(value) => Ok(Self::Id(value)),
3845			Value::IdRef(value) => Ok(Self::IdRef(value)),
3846			other => Err(other),
3847		}
3848	}
3849}
3850impl TryFrom<Value> for NCNameValue {
3851	type Error = Value;
3852	fn try_from(value: Value) -> Result<Self, Value> {
3853		match value {
3854			Value::NCName(value) => Ok(Self::NCName(value)),
3855			Value::Id(value) => Ok(Self::Id(value)),
3856			Value::IdRef(value) => Ok(Self::IdRef(value)),
3857			other => Err(other),
3858		}
3859	}
3860}
3861impl<'a> From<StringValueRef<'a>> for ValueRef<'a> {
3862	fn from(value: StringValueRef<'a>) -> Self {
3863		match value {
3864			StringValueRef::String(value) => Self::String(value),
3865			StringValueRef::NormalizedString(value) => Self::NormalizedString(value),
3866			StringValueRef::Token(value) => Self::Token(value),
3867			StringValueRef::Language(value) => Self::Language(value),
3868			StringValueRef::Name(value) => Self::Name(value),
3869			StringValueRef::NCName(value) => Self::NCName(value),
3870			StringValueRef::Id(value) => Self::Id(value),
3871			StringValueRef::IdRef(value) => Self::IdRef(value),
3872			StringValueRef::NMToken(value) => Self::NMToken(value),
3873		}
3874	}
3875}
3876impl<'a> From<NormalizedStringValueRef<'a>> for ValueRef<'a> {
3877	fn from(value: NormalizedStringValueRef<'a>) -> Self {
3878		match value {
3879			NormalizedStringValueRef::NormalizedString(value) => Self::NormalizedString(value),
3880			NormalizedStringValueRef::Token(value) => Self::Token(value),
3881			NormalizedStringValueRef::Language(value) => Self::Language(value),
3882			NormalizedStringValueRef::Name(value) => Self::Name(value),
3883			NormalizedStringValueRef::NCName(value) => Self::NCName(value),
3884			NormalizedStringValueRef::Id(value) => Self::Id(value),
3885			NormalizedStringValueRef::IdRef(value) => Self::IdRef(value),
3886			NormalizedStringValueRef::NMToken(value) => Self::NMToken(value),
3887		}
3888	}
3889}
3890impl<'a> From<TokenValueRef<'a>> for ValueRef<'a> {
3891	fn from(value: TokenValueRef<'a>) -> Self {
3892		match value {
3893			TokenValueRef::Token(value) => Self::Token(value),
3894			TokenValueRef::Language(value) => Self::Language(value),
3895			TokenValueRef::Name(value) => Self::Name(value),
3896			TokenValueRef::NCName(value) => Self::NCName(value),
3897			TokenValueRef::Id(value) => Self::Id(value),
3898			TokenValueRef::IdRef(value) => Self::IdRef(value),
3899			TokenValueRef::NMToken(value) => Self::NMToken(value),
3900		}
3901	}
3902}
3903impl<'a> From<NameValueRef<'a>> for ValueRef<'a> {
3904	fn from(value: NameValueRef<'a>) -> Self {
3905		match value {
3906			NameValueRef::Name(value) => Self::Name(value),
3907			NameValueRef::NCName(value) => Self::NCName(value),
3908			NameValueRef::Id(value) => Self::Id(value),
3909			NameValueRef::IdRef(value) => Self::IdRef(value),
3910		}
3911	}
3912}
3913impl<'a> From<NCNameValueRef<'a>> for ValueRef<'a> {
3914	fn from(value: NCNameValueRef<'a>) -> Self {
3915		match value {
3916			NCNameValueRef::NCName(value) => Self::NCName(value),
3917			NCNameValueRef::Id(value) => Self::Id(value),
3918			NCNameValueRef::IdRef(value) => Self::IdRef(value),
3919		}
3920	}
3921}
3922impl<'a> TryFrom<ValueRef<'a>> for StringValueRef<'a> {
3923	type Error = ValueRef<'a>;
3924	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
3925		match value {
3926			ValueRef::String(value) => Ok(Self::String(value)),
3927			ValueRef::NormalizedString(value) => Ok(Self::NormalizedString(value)),
3928			ValueRef::Token(value) => Ok(Self::Token(value)),
3929			ValueRef::Language(value) => Ok(Self::Language(value)),
3930			ValueRef::Name(value) => Ok(Self::Name(value)),
3931			ValueRef::NCName(value) => Ok(Self::NCName(value)),
3932			ValueRef::Id(value) => Ok(Self::Id(value)),
3933			ValueRef::IdRef(value) => Ok(Self::IdRef(value)),
3934			ValueRef::NMToken(value) => Ok(Self::NMToken(value)),
3935			other => Err(other),
3936		}
3937	}
3938}
3939impl<'a> TryFrom<ValueRef<'a>> for NormalizedStringValueRef<'a> {
3940	type Error = ValueRef<'a>;
3941	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
3942		match value {
3943			ValueRef::NormalizedString(value) => Ok(Self::NormalizedString(value)),
3944			ValueRef::Token(value) => Ok(Self::Token(value)),
3945			ValueRef::Language(value) => Ok(Self::Language(value)),
3946			ValueRef::Name(value) => Ok(Self::Name(value)),
3947			ValueRef::NCName(value) => Ok(Self::NCName(value)),
3948			ValueRef::Id(value) => Ok(Self::Id(value)),
3949			ValueRef::IdRef(value) => Ok(Self::IdRef(value)),
3950			ValueRef::NMToken(value) => Ok(Self::NMToken(value)),
3951			other => Err(other),
3952		}
3953	}
3954}
3955impl<'a> TryFrom<ValueRef<'a>> for TokenValueRef<'a> {
3956	type Error = ValueRef<'a>;
3957	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
3958		match value {
3959			ValueRef::Token(value) => Ok(Self::Token(value)),
3960			ValueRef::Language(value) => Ok(Self::Language(value)),
3961			ValueRef::Name(value) => Ok(Self::Name(value)),
3962			ValueRef::NCName(value) => Ok(Self::NCName(value)),
3963			ValueRef::Id(value) => Ok(Self::Id(value)),
3964			ValueRef::IdRef(value) => Ok(Self::IdRef(value)),
3965			ValueRef::NMToken(value) => Ok(Self::NMToken(value)),
3966			other => Err(other),
3967		}
3968	}
3969}
3970impl<'a> TryFrom<ValueRef<'a>> for NameValueRef<'a> {
3971	type Error = ValueRef<'a>;
3972	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
3973		match value {
3974			ValueRef::Name(value) => Ok(Self::Name(value)),
3975			ValueRef::NCName(value) => Ok(Self::NCName(value)),
3976			ValueRef::Id(value) => Ok(Self::Id(value)),
3977			ValueRef::IdRef(value) => Ok(Self::IdRef(value)),
3978			other => Err(other),
3979		}
3980	}
3981}
3982impl<'a> TryFrom<ValueRef<'a>> for NCNameValueRef<'a> {
3983	type Error = ValueRef<'a>;
3984	fn try_from(value: ValueRef<'a>) -> Result<Self, ValueRef<'a>> {
3985		match value {
3986			ValueRef::NCName(value) => Ok(Self::NCName(value)),
3987			ValueRef::Id(value) => Ok(Self::Id(value)),
3988			ValueRef::IdRef(value) => Ok(Self::IdRef(value)),
3989			other => Err(other),
3990		}
3991	}
3992}
3993/// Any specialized [`str`] value.
3994#[derive(Debug, Clone)]
3995pub enum StringValue {
3996	String(String),
3997	NormalizedString(NormalizedString),
3998	Token(TokenBuf),
3999	Language(LanguageBuf),
4000	Name(NameBuf),
4001	NCName(NCNameBuf),
4002	Id(IdBuf),
4003	IdRef(IdRefBuf),
4004	NMToken(NMTokenBuf),
4005}
4006impl StringValue {
4007	pub fn datatype(&self) -> StringDatatype {
4008		match self {
4009			Self::String(_) => StringDatatype::String,
4010			Self::NormalizedString(_) => {
4011				StringDatatype::NormalizedString(NormalizedStringDatatype::NormalizedString)
4012			}
4013			Self::Token(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4014				TokenDatatype::Token,
4015			)),
4016			Self::Language(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4017				TokenDatatype::Language,
4018			)),
4019			Self::Name(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4020				TokenDatatype::Name(NameDatatype::Name),
4021			)),
4022			Self::NCName(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4023				TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::NCName)),
4024			)),
4025			Self::Id(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4026				TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::Id)),
4027			)),
4028			Self::IdRef(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4029				TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::IdRef)),
4030			)),
4031			Self::NMToken(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4032				TokenDatatype::NMToken,
4033			)),
4034		}
4035	}
4036}
4037impl XsdValue for StringValue {
4038	fn datatype(&self) -> Datatype {
4039		self.datatype().into()
4040	}
4041}
4042impl fmt::Display for StringValue {
4043	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4044		match self {
4045			Self::String(v) => v.fmt(f),
4046			Self::NormalizedString(v) => v.fmt(f),
4047			Self::Token(v) => v.fmt(f),
4048			Self::Language(v) => v.fmt(f),
4049			Self::Name(v) => v.fmt(f),
4050			Self::NCName(v) => v.fmt(f),
4051			Self::Id(v) => v.fmt(f),
4052			Self::IdRef(v) => v.fmt(f),
4053			Self::NMToken(v) => v.fmt(f),
4054		}
4055	}
4056}
4057impl From<NormalizedStringValue> for StringValue {
4058	fn from(value: NormalizedStringValue) -> Self {
4059		match value {
4060			NormalizedStringValue::NormalizedString(value) => Self::NormalizedString(value),
4061			NormalizedStringValue::Token(value) => Self::Token(value),
4062			NormalizedStringValue::Language(value) => Self::Language(value),
4063			NormalizedStringValue::Name(value) => Self::Name(value),
4064			NormalizedStringValue::NCName(value) => Self::NCName(value),
4065			NormalizedStringValue::Id(value) => Self::Id(value),
4066			NormalizedStringValue::IdRef(value) => Self::IdRef(value),
4067			NormalizedStringValue::NMToken(value) => Self::NMToken(value),
4068		}
4069	}
4070}
4071impl From<TokenValue> for StringValue {
4072	fn from(value: TokenValue) -> Self {
4073		match value {
4074			TokenValue::Token(value) => Self::Token(value),
4075			TokenValue::Language(value) => Self::Language(value),
4076			TokenValue::Name(value) => Self::Name(value),
4077			TokenValue::NCName(value) => Self::NCName(value),
4078			TokenValue::Id(value) => Self::Id(value),
4079			TokenValue::IdRef(value) => Self::IdRef(value),
4080			TokenValue::NMToken(value) => Self::NMToken(value),
4081		}
4082	}
4083}
4084impl From<NameValue> for StringValue {
4085	fn from(value: NameValue) -> Self {
4086		match value {
4087			NameValue::Name(value) => Self::Name(value),
4088			NameValue::NCName(value) => Self::NCName(value),
4089			NameValue::Id(value) => Self::Id(value),
4090			NameValue::IdRef(value) => Self::IdRef(value),
4091		}
4092	}
4093}
4094impl From<NCNameValue> for StringValue {
4095	fn from(value: NCNameValue) -> Self {
4096		match value {
4097			NCNameValue::NCName(value) => Self::NCName(value),
4098			NCNameValue::Id(value) => Self::Id(value),
4099			NCNameValue::IdRef(value) => Self::IdRef(value),
4100		}
4101	}
4102}
4103impl TryFrom<StringValue> for NormalizedStringValue {
4104	type Error = StringValue;
4105	fn try_from(value: StringValue) -> Result<Self, StringValue> {
4106		match value {
4107			StringValue::NormalizedString(value) => Ok(Self::NormalizedString(value)),
4108			StringValue::Token(value) => Ok(Self::Token(value)),
4109			StringValue::Language(value) => Ok(Self::Language(value)),
4110			StringValue::Name(value) => Ok(Self::Name(value)),
4111			StringValue::NCName(value) => Ok(Self::NCName(value)),
4112			StringValue::Id(value) => Ok(Self::Id(value)),
4113			StringValue::IdRef(value) => Ok(Self::IdRef(value)),
4114			StringValue::NMToken(value) => Ok(Self::NMToken(value)),
4115			other => Err(other),
4116		}
4117	}
4118}
4119impl TryFrom<StringValue> for TokenValue {
4120	type Error = StringValue;
4121	fn try_from(value: StringValue) -> Result<Self, StringValue> {
4122		match value {
4123			StringValue::Token(value) => Ok(Self::Token(value)),
4124			StringValue::Language(value) => Ok(Self::Language(value)),
4125			StringValue::Name(value) => Ok(Self::Name(value)),
4126			StringValue::NCName(value) => Ok(Self::NCName(value)),
4127			StringValue::Id(value) => Ok(Self::Id(value)),
4128			StringValue::IdRef(value) => Ok(Self::IdRef(value)),
4129			StringValue::NMToken(value) => Ok(Self::NMToken(value)),
4130			other => Err(other),
4131		}
4132	}
4133}
4134impl TryFrom<StringValue> for NameValue {
4135	type Error = StringValue;
4136	fn try_from(value: StringValue) -> Result<Self, StringValue> {
4137		match value {
4138			StringValue::Name(value) => Ok(Self::Name(value)),
4139			StringValue::NCName(value) => Ok(Self::NCName(value)),
4140			StringValue::Id(value) => Ok(Self::Id(value)),
4141			StringValue::IdRef(value) => Ok(Self::IdRef(value)),
4142			other => Err(other),
4143		}
4144	}
4145}
4146impl TryFrom<StringValue> for NCNameValue {
4147	type Error = StringValue;
4148	fn try_from(value: StringValue) -> Result<Self, StringValue> {
4149		match value {
4150			StringValue::NCName(value) => Ok(Self::NCName(value)),
4151			StringValue::Id(value) => Ok(Self::Id(value)),
4152			StringValue::IdRef(value) => Ok(Self::IdRef(value)),
4153			other => Err(other),
4154		}
4155	}
4156}
4157/// [`NormalizedStr`] datatype variants.
4158#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4159pub enum NormalizedStringDatatype {
4160	NormalizedString,
4161	Token(TokenDatatype),
4162}
4163impl NormalizedStringDatatype {
4164	pub fn from_iri(iri: &Iri) -> Option<Self> {
4165		if iri == XSD_NORMALIZED_STRING {
4166			return Some(Self::NormalizedString);
4167		}
4168		if let Some(t) = TokenDatatype::from_iri(iri) {
4169			return Some(Self::Token(t));
4170		}
4171		None
4172	}
4173	pub fn iri(&self) -> &'static Iri {
4174		match self {
4175			Self::NormalizedString => XSD_NORMALIZED_STRING,
4176			Self::Token(t) => t.iri(),
4177		}
4178	}
4179	pub fn parse(&self, value: &str) -> Result<NormalizedStringValue, ParseError> {
4180		match self {
4181			Self::NormalizedString => ParseXsd::parse_xsd(value)
4182				.map(NormalizedStringValue::NormalizedString)
4183				.map_err(|_| ParseError),
4184			Self::Token(t) => t.parse(value).map(Into::into),
4185		}
4186	}
4187}
4188impl From<TokenDatatype> for NormalizedStringDatatype {
4189	fn from(value: TokenDatatype) -> Self {
4190		Self::Token(value)
4191	}
4192}
4193impl From<NameDatatype> for NormalizedStringDatatype {
4194	fn from(value: NameDatatype) -> Self {
4195		Self::Token(TokenDatatype::Name(value))
4196	}
4197}
4198impl From<NCNameDatatype> for NormalizedStringDatatype {
4199	fn from(value: NCNameDatatype) -> Self {
4200		Self::Token(TokenDatatype::Name(NameDatatype::NCName(value)))
4201	}
4202}
4203impl TryFrom<NormalizedStringDatatype> for TokenDatatype {
4204	type Error = NormalizedStringDatatype;
4205	fn try_from(value: NormalizedStringDatatype) -> Result<Self, NormalizedStringDatatype> {
4206		match value {
4207			NormalizedStringDatatype::Token(value) => Ok(value),
4208			other => Err(other),
4209		}
4210	}
4211}
4212impl TryFrom<NormalizedStringDatatype> for NameDatatype {
4213	type Error = NormalizedStringDatatype;
4214	fn try_from(value: NormalizedStringDatatype) -> Result<Self, NormalizedStringDatatype> {
4215		match value {
4216			NormalizedStringDatatype::Token(TokenDatatype::Name(value)) => Ok(value),
4217			other => Err(other),
4218		}
4219	}
4220}
4221impl TryFrom<NormalizedStringDatatype> for NCNameDatatype {
4222	type Error = NormalizedStringDatatype;
4223	fn try_from(value: NormalizedStringDatatype) -> Result<Self, NormalizedStringDatatype> {
4224		match value {
4225			NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::NCName(value))) => {
4226				Ok(value)
4227			}
4228			other => Err(other),
4229		}
4230	}
4231}
4232/// Any specialized [`str`] value reference.
4233#[derive(Debug, Clone, Copy)]
4234pub enum StringValueRef<'a> {
4235	String(&'a str),
4236	NormalizedString(&'a NormalizedStr),
4237	Token(&'a Token),
4238	Language(&'a Language),
4239	Name(&'a Name),
4240	NCName(&'a NCName),
4241	Id(&'a Id),
4242	IdRef(&'a IdRef),
4243	NMToken(&'a NMToken),
4244}
4245impl StringValue {
4246	pub fn as_ref(&self) -> StringValueRef {
4247		match self {
4248			Self::String(value) => StringValueRef::String(value),
4249			Self::NormalizedString(value) => StringValueRef::NormalizedString(value),
4250			Self::Token(value) => StringValueRef::Token(value),
4251			Self::Language(value) => StringValueRef::Language(value),
4252			Self::Name(value) => StringValueRef::Name(value),
4253			Self::NCName(value) => StringValueRef::NCName(value),
4254			Self::Id(value) => StringValueRef::Id(value),
4255			Self::IdRef(value) => StringValueRef::IdRef(value),
4256			Self::NMToken(value) => StringValueRef::NMToken(value),
4257		}
4258	}
4259}
4260impl<'a> StringValueRef<'a> {
4261	pub fn datatype(&self) -> StringDatatype {
4262		match self {
4263			Self::String(_) => StringDatatype::String,
4264			Self::NormalizedString(_) => {
4265				StringDatatype::NormalizedString(NormalizedStringDatatype::NormalizedString)
4266			}
4267			Self::Token(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4268				TokenDatatype::Token,
4269			)),
4270			Self::Language(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4271				TokenDatatype::Language,
4272			)),
4273			Self::Name(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4274				TokenDatatype::Name(NameDatatype::Name),
4275			)),
4276			Self::NCName(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4277				TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::NCName)),
4278			)),
4279			Self::Id(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4280				TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::Id)),
4281			)),
4282			Self::IdRef(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4283				TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::IdRef)),
4284			)),
4285			Self::NMToken(_) => StringDatatype::NormalizedString(NormalizedStringDatatype::Token(
4286				TokenDatatype::NMToken,
4287			)),
4288		}
4289	}
4290	pub fn cloned(&self) -> StringValue {
4291		match *self {
4292			Self::String(value) => StringValue::String(value.to_owned()),
4293			Self::NormalizedString(value) => StringValue::NormalizedString(value.to_owned()),
4294			Self::Token(value) => StringValue::Token(value.to_owned()),
4295			Self::Language(value) => StringValue::Language(value.to_owned()),
4296			Self::Name(value) => StringValue::Name(value.to_owned()),
4297			Self::NCName(value) => StringValue::NCName(value.to_owned()),
4298			Self::Id(value) => StringValue::Id(value.to_owned()),
4299			Self::IdRef(value) => StringValue::IdRef(value.to_owned()),
4300			Self::NMToken(value) => StringValue::NMToken(value.to_owned()),
4301		}
4302	}
4303}
4304impl<'a> XsdValue for StringValueRef<'a> {
4305	fn datatype(&self) -> Datatype {
4306		self.datatype().into()
4307	}
4308}
4309impl<'a> fmt::Display for StringValueRef<'a> {
4310	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4311		match self {
4312			Self::String(v) => v.fmt(f),
4313			Self::NormalizedString(v) => v.fmt(f),
4314			Self::Token(v) => v.fmt(f),
4315			Self::Language(v) => v.fmt(f),
4316			Self::Name(v) => v.fmt(f),
4317			Self::NCName(v) => v.fmt(f),
4318			Self::Id(v) => v.fmt(f),
4319			Self::IdRef(v) => v.fmt(f),
4320			Self::NMToken(v) => v.fmt(f),
4321		}
4322	}
4323}
4324impl<'a> From<NormalizedStringValueRef<'a>> for StringValueRef<'a> {
4325	fn from(value: NormalizedStringValueRef<'a>) -> Self {
4326		match value {
4327			NormalizedStringValueRef::NormalizedString(value) => Self::NormalizedString(value),
4328			NormalizedStringValueRef::Token(value) => Self::Token(value),
4329			NormalizedStringValueRef::Language(value) => Self::Language(value),
4330			NormalizedStringValueRef::Name(value) => Self::Name(value),
4331			NormalizedStringValueRef::NCName(value) => Self::NCName(value),
4332			NormalizedStringValueRef::Id(value) => Self::Id(value),
4333			NormalizedStringValueRef::IdRef(value) => Self::IdRef(value),
4334			NormalizedStringValueRef::NMToken(value) => Self::NMToken(value),
4335		}
4336	}
4337}
4338impl<'a> From<TokenValueRef<'a>> for StringValueRef<'a> {
4339	fn from(value: TokenValueRef<'a>) -> Self {
4340		match value {
4341			TokenValueRef::Token(value) => Self::Token(value),
4342			TokenValueRef::Language(value) => Self::Language(value),
4343			TokenValueRef::Name(value) => Self::Name(value),
4344			TokenValueRef::NCName(value) => Self::NCName(value),
4345			TokenValueRef::Id(value) => Self::Id(value),
4346			TokenValueRef::IdRef(value) => Self::IdRef(value),
4347			TokenValueRef::NMToken(value) => Self::NMToken(value),
4348		}
4349	}
4350}
4351impl<'a> From<NameValueRef<'a>> for StringValueRef<'a> {
4352	fn from(value: NameValueRef<'a>) -> Self {
4353		match value {
4354			NameValueRef::Name(value) => Self::Name(value),
4355			NameValueRef::NCName(value) => Self::NCName(value),
4356			NameValueRef::Id(value) => Self::Id(value),
4357			NameValueRef::IdRef(value) => Self::IdRef(value),
4358		}
4359	}
4360}
4361impl<'a> From<NCNameValueRef<'a>> for StringValueRef<'a> {
4362	fn from(value: NCNameValueRef<'a>) -> Self {
4363		match value {
4364			NCNameValueRef::NCName(value) => Self::NCName(value),
4365			NCNameValueRef::Id(value) => Self::Id(value),
4366			NCNameValueRef::IdRef(value) => Self::IdRef(value),
4367		}
4368	}
4369}
4370impl<'a> TryFrom<StringValueRef<'a>> for NormalizedStringValueRef<'a> {
4371	type Error = StringValueRef<'a>;
4372	fn try_from(value: StringValueRef<'a>) -> Result<Self, StringValueRef<'a>> {
4373		match value {
4374			StringValueRef::NormalizedString(value) => Ok(Self::NormalizedString(value)),
4375			StringValueRef::Token(value) => Ok(Self::Token(value)),
4376			StringValueRef::Language(value) => Ok(Self::Language(value)),
4377			StringValueRef::Name(value) => Ok(Self::Name(value)),
4378			StringValueRef::NCName(value) => Ok(Self::NCName(value)),
4379			StringValueRef::Id(value) => Ok(Self::Id(value)),
4380			StringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4381			StringValueRef::NMToken(value) => Ok(Self::NMToken(value)),
4382			other => Err(other),
4383		}
4384	}
4385}
4386impl<'a> TryFrom<StringValueRef<'a>> for TokenValueRef<'a> {
4387	type Error = StringValueRef<'a>;
4388	fn try_from(value: StringValueRef<'a>) -> Result<Self, StringValueRef<'a>> {
4389		match value {
4390			StringValueRef::Token(value) => Ok(Self::Token(value)),
4391			StringValueRef::Language(value) => Ok(Self::Language(value)),
4392			StringValueRef::Name(value) => Ok(Self::Name(value)),
4393			StringValueRef::NCName(value) => Ok(Self::NCName(value)),
4394			StringValueRef::Id(value) => Ok(Self::Id(value)),
4395			StringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4396			StringValueRef::NMToken(value) => Ok(Self::NMToken(value)),
4397			other => Err(other),
4398		}
4399	}
4400}
4401impl<'a> TryFrom<StringValueRef<'a>> for NameValueRef<'a> {
4402	type Error = StringValueRef<'a>;
4403	fn try_from(value: StringValueRef<'a>) -> Result<Self, StringValueRef<'a>> {
4404		match value {
4405			StringValueRef::Name(value) => Ok(Self::Name(value)),
4406			StringValueRef::NCName(value) => Ok(Self::NCName(value)),
4407			StringValueRef::Id(value) => Ok(Self::Id(value)),
4408			StringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4409			other => Err(other),
4410		}
4411	}
4412}
4413impl<'a> TryFrom<StringValueRef<'a>> for NCNameValueRef<'a> {
4414	type Error = StringValueRef<'a>;
4415	fn try_from(value: StringValueRef<'a>) -> Result<Self, StringValueRef<'a>> {
4416		match value {
4417			StringValueRef::NCName(value) => Ok(Self::NCName(value)),
4418			StringValueRef::Id(value) => Ok(Self::Id(value)),
4419			StringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4420			other => Err(other),
4421		}
4422	}
4423}
4424/// Any specialized [`NormalizedStr`] value.
4425#[derive(Debug, Clone)]
4426pub enum NormalizedStringValue {
4427	NormalizedString(NormalizedString),
4428	Token(TokenBuf),
4429	Language(LanguageBuf),
4430	Name(NameBuf),
4431	NCName(NCNameBuf),
4432	Id(IdBuf),
4433	IdRef(IdRefBuf),
4434	NMToken(NMTokenBuf),
4435}
4436impl NormalizedStringValue {
4437	pub fn datatype(&self) -> NormalizedStringDatatype {
4438		match self {
4439			Self::NormalizedString(_) => NormalizedStringDatatype::NormalizedString,
4440			Self::Token(_) => NormalizedStringDatatype::Token(TokenDatatype::Token),
4441			Self::Language(_) => NormalizedStringDatatype::Token(TokenDatatype::Language),
4442			Self::Name(_) => {
4443				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::Name))
4444			}
4445			Self::NCName(_) => NormalizedStringDatatype::Token(TokenDatatype::Name(
4446				NameDatatype::NCName(NCNameDatatype::NCName),
4447			)),
4448			Self::Id(_) => NormalizedStringDatatype::Token(TokenDatatype::Name(
4449				NameDatatype::NCName(NCNameDatatype::Id),
4450			)),
4451			Self::IdRef(_) => NormalizedStringDatatype::Token(TokenDatatype::Name(
4452				NameDatatype::NCName(NCNameDatatype::IdRef),
4453			)),
4454			Self::NMToken(_) => NormalizedStringDatatype::Token(TokenDatatype::NMToken),
4455		}
4456	}
4457}
4458impl XsdValue for NormalizedStringValue {
4459	fn datatype(&self) -> Datatype {
4460		self.datatype().into()
4461	}
4462}
4463impl fmt::Display for NormalizedStringValue {
4464	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4465		match self {
4466			Self::NormalizedString(v) => v.fmt(f),
4467			Self::Token(v) => v.fmt(f),
4468			Self::Language(v) => v.fmt(f),
4469			Self::Name(v) => v.fmt(f),
4470			Self::NCName(v) => v.fmt(f),
4471			Self::Id(v) => v.fmt(f),
4472			Self::IdRef(v) => v.fmt(f),
4473			Self::NMToken(v) => v.fmt(f),
4474		}
4475	}
4476}
4477impl From<TokenValue> for NormalizedStringValue {
4478	fn from(value: TokenValue) -> Self {
4479		match value {
4480			TokenValue::Token(value) => Self::Token(value),
4481			TokenValue::Language(value) => Self::Language(value),
4482			TokenValue::Name(value) => Self::Name(value),
4483			TokenValue::NCName(value) => Self::NCName(value),
4484			TokenValue::Id(value) => Self::Id(value),
4485			TokenValue::IdRef(value) => Self::IdRef(value),
4486			TokenValue::NMToken(value) => Self::NMToken(value),
4487		}
4488	}
4489}
4490impl From<NameValue> for NormalizedStringValue {
4491	fn from(value: NameValue) -> Self {
4492		match value {
4493			NameValue::Name(value) => Self::Name(value),
4494			NameValue::NCName(value) => Self::NCName(value),
4495			NameValue::Id(value) => Self::Id(value),
4496			NameValue::IdRef(value) => Self::IdRef(value),
4497		}
4498	}
4499}
4500impl From<NCNameValue> for NormalizedStringValue {
4501	fn from(value: NCNameValue) -> Self {
4502		match value {
4503			NCNameValue::NCName(value) => Self::NCName(value),
4504			NCNameValue::Id(value) => Self::Id(value),
4505			NCNameValue::IdRef(value) => Self::IdRef(value),
4506		}
4507	}
4508}
4509impl TryFrom<NormalizedStringValue> for TokenValue {
4510	type Error = NormalizedStringValue;
4511	fn try_from(value: NormalizedStringValue) -> Result<Self, NormalizedStringValue> {
4512		match value {
4513			NormalizedStringValue::Token(value) => Ok(Self::Token(value)),
4514			NormalizedStringValue::Language(value) => Ok(Self::Language(value)),
4515			NormalizedStringValue::Name(value) => Ok(Self::Name(value)),
4516			NormalizedStringValue::NCName(value) => Ok(Self::NCName(value)),
4517			NormalizedStringValue::Id(value) => Ok(Self::Id(value)),
4518			NormalizedStringValue::IdRef(value) => Ok(Self::IdRef(value)),
4519			NormalizedStringValue::NMToken(value) => Ok(Self::NMToken(value)),
4520			other => Err(other),
4521		}
4522	}
4523}
4524impl TryFrom<NormalizedStringValue> for NameValue {
4525	type Error = NormalizedStringValue;
4526	fn try_from(value: NormalizedStringValue) -> Result<Self, NormalizedStringValue> {
4527		match value {
4528			NormalizedStringValue::Name(value) => Ok(Self::Name(value)),
4529			NormalizedStringValue::NCName(value) => Ok(Self::NCName(value)),
4530			NormalizedStringValue::Id(value) => Ok(Self::Id(value)),
4531			NormalizedStringValue::IdRef(value) => Ok(Self::IdRef(value)),
4532			other => Err(other),
4533		}
4534	}
4535}
4536impl TryFrom<NormalizedStringValue> for NCNameValue {
4537	type Error = NormalizedStringValue;
4538	fn try_from(value: NormalizedStringValue) -> Result<Self, NormalizedStringValue> {
4539		match value {
4540			NormalizedStringValue::NCName(value) => Ok(Self::NCName(value)),
4541			NormalizedStringValue::Id(value) => Ok(Self::Id(value)),
4542			NormalizedStringValue::IdRef(value) => Ok(Self::IdRef(value)),
4543			other => Err(other),
4544		}
4545	}
4546}
4547/// [`Token`] datatype variants.
4548#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4549pub enum TokenDatatype {
4550	Token,
4551	Language,
4552	Name(NameDatatype),
4553	NMToken,
4554}
4555impl TokenDatatype {
4556	pub fn from_iri(iri: &Iri) -> Option<Self> {
4557		if iri == XSD_TOKEN {
4558			return Some(Self::Token);
4559		}
4560		if iri == XSD_LANGUAGE {
4561			return Some(Self::Language);
4562		}
4563		if let Some(t) = NameDatatype::from_iri(iri) {
4564			return Some(Self::Name(t));
4565		}
4566		if iri == XSD_NMTOKEN {
4567			return Some(Self::NMToken);
4568		}
4569		None
4570	}
4571	pub fn iri(&self) -> &'static Iri {
4572		match self {
4573			Self::Token => XSD_TOKEN,
4574			Self::Language => XSD_LANGUAGE,
4575			Self::Name(t) => t.iri(),
4576			Self::NMToken => XSD_NMTOKEN,
4577		}
4578	}
4579	pub fn parse(&self, value: &str) -> Result<TokenValue, ParseError> {
4580		match self {
4581			Self::Token => ParseXsd::parse_xsd(value)
4582				.map(TokenValue::Token)
4583				.map_err(|_| ParseError),
4584			Self::Language => ParseXsd::parse_xsd(value)
4585				.map(TokenValue::Language)
4586				.map_err(|_| ParseError),
4587			Self::Name(t) => t.parse(value).map(Into::into),
4588			Self::NMToken => ParseXsd::parse_xsd(value)
4589				.map(TokenValue::NMToken)
4590				.map_err(|_| ParseError),
4591		}
4592	}
4593}
4594impl From<NameDatatype> for TokenDatatype {
4595	fn from(value: NameDatatype) -> Self {
4596		Self::Name(value)
4597	}
4598}
4599impl From<NCNameDatatype> for TokenDatatype {
4600	fn from(value: NCNameDatatype) -> Self {
4601		Self::Name(NameDatatype::NCName(value))
4602	}
4603}
4604impl TryFrom<TokenDatatype> for NameDatatype {
4605	type Error = TokenDatatype;
4606	fn try_from(value: TokenDatatype) -> Result<Self, TokenDatatype> {
4607		match value {
4608			TokenDatatype::Name(value) => Ok(value),
4609			other => Err(other),
4610		}
4611	}
4612}
4613impl TryFrom<TokenDatatype> for NCNameDatatype {
4614	type Error = TokenDatatype;
4615	fn try_from(value: TokenDatatype) -> Result<Self, TokenDatatype> {
4616		match value {
4617			TokenDatatype::Name(NameDatatype::NCName(value)) => Ok(value),
4618			other => Err(other),
4619		}
4620	}
4621}
4622/// Any specialized [`NormalizedStr`] value reference.
4623#[derive(Debug, Clone, Copy)]
4624pub enum NormalizedStringValueRef<'a> {
4625	NormalizedString(&'a NormalizedStr),
4626	Token(&'a Token),
4627	Language(&'a Language),
4628	Name(&'a Name),
4629	NCName(&'a NCName),
4630	Id(&'a Id),
4631	IdRef(&'a IdRef),
4632	NMToken(&'a NMToken),
4633}
4634impl NormalizedStringValue {
4635	pub fn as_ref(&self) -> NormalizedStringValueRef {
4636		match self {
4637			Self::NormalizedString(value) => NormalizedStringValueRef::NormalizedString(value),
4638			Self::Token(value) => NormalizedStringValueRef::Token(value),
4639			Self::Language(value) => NormalizedStringValueRef::Language(value),
4640			Self::Name(value) => NormalizedStringValueRef::Name(value),
4641			Self::NCName(value) => NormalizedStringValueRef::NCName(value),
4642			Self::Id(value) => NormalizedStringValueRef::Id(value),
4643			Self::IdRef(value) => NormalizedStringValueRef::IdRef(value),
4644			Self::NMToken(value) => NormalizedStringValueRef::NMToken(value),
4645		}
4646	}
4647}
4648impl<'a> NormalizedStringValueRef<'a> {
4649	pub fn datatype(&self) -> NormalizedStringDatatype {
4650		match self {
4651			Self::NormalizedString(_) => NormalizedStringDatatype::NormalizedString,
4652			Self::Token(_) => NormalizedStringDatatype::Token(TokenDatatype::Token),
4653			Self::Language(_) => NormalizedStringDatatype::Token(TokenDatatype::Language),
4654			Self::Name(_) => {
4655				NormalizedStringDatatype::Token(TokenDatatype::Name(NameDatatype::Name))
4656			}
4657			Self::NCName(_) => NormalizedStringDatatype::Token(TokenDatatype::Name(
4658				NameDatatype::NCName(NCNameDatatype::NCName),
4659			)),
4660			Self::Id(_) => NormalizedStringDatatype::Token(TokenDatatype::Name(
4661				NameDatatype::NCName(NCNameDatatype::Id),
4662			)),
4663			Self::IdRef(_) => NormalizedStringDatatype::Token(TokenDatatype::Name(
4664				NameDatatype::NCName(NCNameDatatype::IdRef),
4665			)),
4666			Self::NMToken(_) => NormalizedStringDatatype::Token(TokenDatatype::NMToken),
4667		}
4668	}
4669	pub fn cloned(&self) -> NormalizedStringValue {
4670		match *self {
4671			Self::NormalizedString(value) => {
4672				NormalizedStringValue::NormalizedString(value.to_owned())
4673			}
4674			Self::Token(value) => NormalizedStringValue::Token(value.to_owned()),
4675			Self::Language(value) => NormalizedStringValue::Language(value.to_owned()),
4676			Self::Name(value) => NormalizedStringValue::Name(value.to_owned()),
4677			Self::NCName(value) => NormalizedStringValue::NCName(value.to_owned()),
4678			Self::Id(value) => NormalizedStringValue::Id(value.to_owned()),
4679			Self::IdRef(value) => NormalizedStringValue::IdRef(value.to_owned()),
4680			Self::NMToken(value) => NormalizedStringValue::NMToken(value.to_owned()),
4681		}
4682	}
4683}
4684impl<'a> XsdValue for NormalizedStringValueRef<'a> {
4685	fn datatype(&self) -> Datatype {
4686		self.datatype().into()
4687	}
4688}
4689impl<'a> fmt::Display for NormalizedStringValueRef<'a> {
4690	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4691		match self {
4692			Self::NormalizedString(v) => v.fmt(f),
4693			Self::Token(v) => v.fmt(f),
4694			Self::Language(v) => v.fmt(f),
4695			Self::Name(v) => v.fmt(f),
4696			Self::NCName(v) => v.fmt(f),
4697			Self::Id(v) => v.fmt(f),
4698			Self::IdRef(v) => v.fmt(f),
4699			Self::NMToken(v) => v.fmt(f),
4700		}
4701	}
4702}
4703impl<'a> From<TokenValueRef<'a>> for NormalizedStringValueRef<'a> {
4704	fn from(value: TokenValueRef<'a>) -> Self {
4705		match value {
4706			TokenValueRef::Token(value) => Self::Token(value),
4707			TokenValueRef::Language(value) => Self::Language(value),
4708			TokenValueRef::Name(value) => Self::Name(value),
4709			TokenValueRef::NCName(value) => Self::NCName(value),
4710			TokenValueRef::Id(value) => Self::Id(value),
4711			TokenValueRef::IdRef(value) => Self::IdRef(value),
4712			TokenValueRef::NMToken(value) => Self::NMToken(value),
4713		}
4714	}
4715}
4716impl<'a> From<NameValueRef<'a>> for NormalizedStringValueRef<'a> {
4717	fn from(value: NameValueRef<'a>) -> Self {
4718		match value {
4719			NameValueRef::Name(value) => Self::Name(value),
4720			NameValueRef::NCName(value) => Self::NCName(value),
4721			NameValueRef::Id(value) => Self::Id(value),
4722			NameValueRef::IdRef(value) => Self::IdRef(value),
4723		}
4724	}
4725}
4726impl<'a> From<NCNameValueRef<'a>> for NormalizedStringValueRef<'a> {
4727	fn from(value: NCNameValueRef<'a>) -> Self {
4728		match value {
4729			NCNameValueRef::NCName(value) => Self::NCName(value),
4730			NCNameValueRef::Id(value) => Self::Id(value),
4731			NCNameValueRef::IdRef(value) => Self::IdRef(value),
4732		}
4733	}
4734}
4735impl<'a> TryFrom<NormalizedStringValueRef<'a>> for TokenValueRef<'a> {
4736	type Error = NormalizedStringValueRef<'a>;
4737	fn try_from(value: NormalizedStringValueRef<'a>) -> Result<Self, NormalizedStringValueRef<'a>> {
4738		match value {
4739			NormalizedStringValueRef::Token(value) => Ok(Self::Token(value)),
4740			NormalizedStringValueRef::Language(value) => Ok(Self::Language(value)),
4741			NormalizedStringValueRef::Name(value) => Ok(Self::Name(value)),
4742			NormalizedStringValueRef::NCName(value) => Ok(Self::NCName(value)),
4743			NormalizedStringValueRef::Id(value) => Ok(Self::Id(value)),
4744			NormalizedStringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4745			NormalizedStringValueRef::NMToken(value) => Ok(Self::NMToken(value)),
4746			other => Err(other),
4747		}
4748	}
4749}
4750impl<'a> TryFrom<NormalizedStringValueRef<'a>> for NameValueRef<'a> {
4751	type Error = NormalizedStringValueRef<'a>;
4752	fn try_from(value: NormalizedStringValueRef<'a>) -> Result<Self, NormalizedStringValueRef<'a>> {
4753		match value {
4754			NormalizedStringValueRef::Name(value) => Ok(Self::Name(value)),
4755			NormalizedStringValueRef::NCName(value) => Ok(Self::NCName(value)),
4756			NormalizedStringValueRef::Id(value) => Ok(Self::Id(value)),
4757			NormalizedStringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4758			other => Err(other),
4759		}
4760	}
4761}
4762impl<'a> TryFrom<NormalizedStringValueRef<'a>> for NCNameValueRef<'a> {
4763	type Error = NormalizedStringValueRef<'a>;
4764	fn try_from(value: NormalizedStringValueRef<'a>) -> Result<Self, NormalizedStringValueRef<'a>> {
4765		match value {
4766			NormalizedStringValueRef::NCName(value) => Ok(Self::NCName(value)),
4767			NormalizedStringValueRef::Id(value) => Ok(Self::Id(value)),
4768			NormalizedStringValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4769			other => Err(other),
4770		}
4771	}
4772}
4773/// Any specialized [`Token`] value.
4774#[derive(Debug, Clone)]
4775pub enum TokenValue {
4776	Token(TokenBuf),
4777	Language(LanguageBuf),
4778	Name(NameBuf),
4779	NCName(NCNameBuf),
4780	Id(IdBuf),
4781	IdRef(IdRefBuf),
4782	NMToken(NMTokenBuf),
4783}
4784impl TokenValue {
4785	pub fn datatype(&self) -> TokenDatatype {
4786		match self {
4787			Self::Token(_) => TokenDatatype::Token,
4788			Self::Language(_) => TokenDatatype::Language,
4789			Self::Name(_) => TokenDatatype::Name(NameDatatype::Name),
4790			Self::NCName(_) => TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::NCName)),
4791			Self::Id(_) => TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::Id)),
4792			Self::IdRef(_) => TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::IdRef)),
4793			Self::NMToken(_) => TokenDatatype::NMToken,
4794		}
4795	}
4796}
4797impl XsdValue for TokenValue {
4798	fn datatype(&self) -> Datatype {
4799		self.datatype().into()
4800	}
4801}
4802impl fmt::Display for TokenValue {
4803	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4804		match self {
4805			Self::Token(v) => v.fmt(f),
4806			Self::Language(v) => v.fmt(f),
4807			Self::Name(v) => v.fmt(f),
4808			Self::NCName(v) => v.fmt(f),
4809			Self::Id(v) => v.fmt(f),
4810			Self::IdRef(v) => v.fmt(f),
4811			Self::NMToken(v) => v.fmt(f),
4812		}
4813	}
4814}
4815impl From<NameValue> for TokenValue {
4816	fn from(value: NameValue) -> Self {
4817		match value {
4818			NameValue::Name(value) => Self::Name(value),
4819			NameValue::NCName(value) => Self::NCName(value),
4820			NameValue::Id(value) => Self::Id(value),
4821			NameValue::IdRef(value) => Self::IdRef(value),
4822		}
4823	}
4824}
4825impl From<NCNameValue> for TokenValue {
4826	fn from(value: NCNameValue) -> Self {
4827		match value {
4828			NCNameValue::NCName(value) => Self::NCName(value),
4829			NCNameValue::Id(value) => Self::Id(value),
4830			NCNameValue::IdRef(value) => Self::IdRef(value),
4831		}
4832	}
4833}
4834impl TryFrom<TokenValue> for NameValue {
4835	type Error = TokenValue;
4836	fn try_from(value: TokenValue) -> Result<Self, TokenValue> {
4837		match value {
4838			TokenValue::Name(value) => Ok(Self::Name(value)),
4839			TokenValue::NCName(value) => Ok(Self::NCName(value)),
4840			TokenValue::Id(value) => Ok(Self::Id(value)),
4841			TokenValue::IdRef(value) => Ok(Self::IdRef(value)),
4842			other => Err(other),
4843		}
4844	}
4845}
4846impl TryFrom<TokenValue> for NCNameValue {
4847	type Error = TokenValue;
4848	fn try_from(value: TokenValue) -> Result<Self, TokenValue> {
4849		match value {
4850			TokenValue::NCName(value) => Ok(Self::NCName(value)),
4851			TokenValue::Id(value) => Ok(Self::Id(value)),
4852			TokenValue::IdRef(value) => Ok(Self::IdRef(value)),
4853			other => Err(other),
4854		}
4855	}
4856}
4857/// [`Name`] datatype variants.
4858#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4859pub enum NameDatatype {
4860	Name,
4861	NCName(NCNameDatatype),
4862}
4863impl NameDatatype {
4864	pub fn from_iri(iri: &Iri) -> Option<Self> {
4865		if iri == XSD_NAME {
4866			return Some(Self::Name);
4867		}
4868		if let Some(t) = NCNameDatatype::from_iri(iri) {
4869			return Some(Self::NCName(t));
4870		}
4871		None
4872	}
4873	pub fn iri(&self) -> &'static Iri {
4874		match self {
4875			Self::Name => XSD_NAME,
4876			Self::NCName(t) => t.iri(),
4877		}
4878	}
4879	pub fn parse(&self, value: &str) -> Result<NameValue, ParseError> {
4880		match self {
4881			Self::Name => ParseXsd::parse_xsd(value)
4882				.map(NameValue::Name)
4883				.map_err(|_| ParseError),
4884			Self::NCName(t) => t.parse(value).map(Into::into),
4885		}
4886	}
4887}
4888impl From<NCNameDatatype> for NameDatatype {
4889	fn from(value: NCNameDatatype) -> Self {
4890		Self::NCName(value)
4891	}
4892}
4893impl TryFrom<NameDatatype> for NCNameDatatype {
4894	type Error = NameDatatype;
4895	fn try_from(value: NameDatatype) -> Result<Self, NameDatatype> {
4896		match value {
4897			NameDatatype::NCName(value) => Ok(value),
4898			other => Err(other),
4899		}
4900	}
4901}
4902/// Any specialized [`Token`] value reference.
4903#[derive(Debug, Clone, Copy)]
4904pub enum TokenValueRef<'a> {
4905	Token(&'a Token),
4906	Language(&'a Language),
4907	Name(&'a Name),
4908	NCName(&'a NCName),
4909	Id(&'a Id),
4910	IdRef(&'a IdRef),
4911	NMToken(&'a NMToken),
4912}
4913impl TokenValue {
4914	pub fn as_ref(&self) -> TokenValueRef {
4915		match self {
4916			Self::Token(value) => TokenValueRef::Token(value),
4917			Self::Language(value) => TokenValueRef::Language(value),
4918			Self::Name(value) => TokenValueRef::Name(value),
4919			Self::NCName(value) => TokenValueRef::NCName(value),
4920			Self::Id(value) => TokenValueRef::Id(value),
4921			Self::IdRef(value) => TokenValueRef::IdRef(value),
4922			Self::NMToken(value) => TokenValueRef::NMToken(value),
4923		}
4924	}
4925}
4926impl<'a> TokenValueRef<'a> {
4927	pub fn datatype(&self) -> TokenDatatype {
4928		match self {
4929			Self::Token(_) => TokenDatatype::Token,
4930			Self::Language(_) => TokenDatatype::Language,
4931			Self::Name(_) => TokenDatatype::Name(NameDatatype::Name),
4932			Self::NCName(_) => TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::NCName)),
4933			Self::Id(_) => TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::Id)),
4934			Self::IdRef(_) => TokenDatatype::Name(NameDatatype::NCName(NCNameDatatype::IdRef)),
4935			Self::NMToken(_) => TokenDatatype::NMToken,
4936		}
4937	}
4938	pub fn cloned(&self) -> TokenValue {
4939		match *self {
4940			Self::Token(value) => TokenValue::Token(value.to_owned()),
4941			Self::Language(value) => TokenValue::Language(value.to_owned()),
4942			Self::Name(value) => TokenValue::Name(value.to_owned()),
4943			Self::NCName(value) => TokenValue::NCName(value.to_owned()),
4944			Self::Id(value) => TokenValue::Id(value.to_owned()),
4945			Self::IdRef(value) => TokenValue::IdRef(value.to_owned()),
4946			Self::NMToken(value) => TokenValue::NMToken(value.to_owned()),
4947		}
4948	}
4949}
4950impl<'a> XsdValue for TokenValueRef<'a> {
4951	fn datatype(&self) -> Datatype {
4952		self.datatype().into()
4953	}
4954}
4955impl<'a> fmt::Display for TokenValueRef<'a> {
4956	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4957		match self {
4958			Self::Token(v) => v.fmt(f),
4959			Self::Language(v) => v.fmt(f),
4960			Self::Name(v) => v.fmt(f),
4961			Self::NCName(v) => v.fmt(f),
4962			Self::Id(v) => v.fmt(f),
4963			Self::IdRef(v) => v.fmt(f),
4964			Self::NMToken(v) => v.fmt(f),
4965		}
4966	}
4967}
4968impl<'a> From<NameValueRef<'a>> for TokenValueRef<'a> {
4969	fn from(value: NameValueRef<'a>) -> Self {
4970		match value {
4971			NameValueRef::Name(value) => Self::Name(value),
4972			NameValueRef::NCName(value) => Self::NCName(value),
4973			NameValueRef::Id(value) => Self::Id(value),
4974			NameValueRef::IdRef(value) => Self::IdRef(value),
4975		}
4976	}
4977}
4978impl<'a> From<NCNameValueRef<'a>> for TokenValueRef<'a> {
4979	fn from(value: NCNameValueRef<'a>) -> Self {
4980		match value {
4981			NCNameValueRef::NCName(value) => Self::NCName(value),
4982			NCNameValueRef::Id(value) => Self::Id(value),
4983			NCNameValueRef::IdRef(value) => Self::IdRef(value),
4984		}
4985	}
4986}
4987impl<'a> TryFrom<TokenValueRef<'a>> for NameValueRef<'a> {
4988	type Error = TokenValueRef<'a>;
4989	fn try_from(value: TokenValueRef<'a>) -> Result<Self, TokenValueRef<'a>> {
4990		match value {
4991			TokenValueRef::Name(value) => Ok(Self::Name(value)),
4992			TokenValueRef::NCName(value) => Ok(Self::NCName(value)),
4993			TokenValueRef::Id(value) => Ok(Self::Id(value)),
4994			TokenValueRef::IdRef(value) => Ok(Self::IdRef(value)),
4995			other => Err(other),
4996		}
4997	}
4998}
4999impl<'a> TryFrom<TokenValueRef<'a>> for NCNameValueRef<'a> {
5000	type Error = TokenValueRef<'a>;
5001	fn try_from(value: TokenValueRef<'a>) -> Result<Self, TokenValueRef<'a>> {
5002		match value {
5003			TokenValueRef::NCName(value) => Ok(Self::NCName(value)),
5004			TokenValueRef::Id(value) => Ok(Self::Id(value)),
5005			TokenValueRef::IdRef(value) => Ok(Self::IdRef(value)),
5006			other => Err(other),
5007		}
5008	}
5009}
5010/// Any specialized [`Name`] value.
5011#[derive(Debug, Clone)]
5012pub enum NameValue {
5013	Name(NameBuf),
5014	NCName(NCNameBuf),
5015	Id(IdBuf),
5016	IdRef(IdRefBuf),
5017}
5018impl NameValue {
5019	pub fn datatype(&self) -> NameDatatype {
5020		match self {
5021			Self::Name(_) => NameDatatype::Name,
5022			Self::NCName(_) => NameDatatype::NCName(NCNameDatatype::NCName),
5023			Self::Id(_) => NameDatatype::NCName(NCNameDatatype::Id),
5024			Self::IdRef(_) => NameDatatype::NCName(NCNameDatatype::IdRef),
5025		}
5026	}
5027}
5028impl XsdValue for NameValue {
5029	fn datatype(&self) -> Datatype {
5030		self.datatype().into()
5031	}
5032}
5033impl fmt::Display for NameValue {
5034	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5035		match self {
5036			Self::Name(v) => v.fmt(f),
5037			Self::NCName(v) => v.fmt(f),
5038			Self::Id(v) => v.fmt(f),
5039			Self::IdRef(v) => v.fmt(f),
5040		}
5041	}
5042}
5043impl From<NCNameValue> for NameValue {
5044	fn from(value: NCNameValue) -> Self {
5045		match value {
5046			NCNameValue::NCName(value) => Self::NCName(value),
5047			NCNameValue::Id(value) => Self::Id(value),
5048			NCNameValue::IdRef(value) => Self::IdRef(value),
5049		}
5050	}
5051}
5052impl TryFrom<NameValue> for NCNameValue {
5053	type Error = NameValue;
5054	fn try_from(value: NameValue) -> Result<Self, NameValue> {
5055		match value {
5056			NameValue::NCName(value) => Ok(Self::NCName(value)),
5057			NameValue::Id(value) => Ok(Self::Id(value)),
5058			NameValue::IdRef(value) => Ok(Self::IdRef(value)),
5059			other => Err(other),
5060		}
5061	}
5062}
5063/// [`NCName`] datatype variants.
5064#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
5065pub enum NCNameDatatype {
5066	NCName,
5067	Id,
5068	IdRef,
5069}
5070impl NCNameDatatype {
5071	pub fn from_iri(iri: &Iri) -> Option<Self> {
5072		if iri == XSD_NC_NAME {
5073			return Some(Self::NCName);
5074		}
5075		if iri == XSD_ID {
5076			return Some(Self::Id);
5077		}
5078		if iri == XSD_IDREF {
5079			return Some(Self::IdRef);
5080		}
5081		None
5082	}
5083	pub fn iri(&self) -> &'static Iri {
5084		match self {
5085			Self::NCName => XSD_NC_NAME,
5086			Self::Id => XSD_ID,
5087			Self::IdRef => XSD_IDREF,
5088		}
5089	}
5090	pub fn parse(&self, value: &str) -> Result<NCNameValue, ParseError> {
5091		match self {
5092			Self::NCName => ParseXsd::parse_xsd(value)
5093				.map(NCNameValue::NCName)
5094				.map_err(|_| ParseError),
5095			Self::Id => ParseXsd::parse_xsd(value)
5096				.map(NCNameValue::Id)
5097				.map_err(|_| ParseError),
5098			Self::IdRef => ParseXsd::parse_xsd(value)
5099				.map(NCNameValue::IdRef)
5100				.map_err(|_| ParseError),
5101		}
5102	}
5103}
5104/// Any specialized [`Name`] value reference.
5105#[derive(Debug, Clone, Copy)]
5106pub enum NameValueRef<'a> {
5107	Name(&'a Name),
5108	NCName(&'a NCName),
5109	Id(&'a Id),
5110	IdRef(&'a IdRef),
5111}
5112impl NameValue {
5113	pub fn as_ref(&self) -> NameValueRef {
5114		match self {
5115			Self::Name(value) => NameValueRef::Name(value),
5116			Self::NCName(value) => NameValueRef::NCName(value),
5117			Self::Id(value) => NameValueRef::Id(value),
5118			Self::IdRef(value) => NameValueRef::IdRef(value),
5119		}
5120	}
5121}
5122impl<'a> NameValueRef<'a> {
5123	pub fn datatype(&self) -> NameDatatype {
5124		match self {
5125			Self::Name(_) => NameDatatype::Name,
5126			Self::NCName(_) => NameDatatype::NCName(NCNameDatatype::NCName),
5127			Self::Id(_) => NameDatatype::NCName(NCNameDatatype::Id),
5128			Self::IdRef(_) => NameDatatype::NCName(NCNameDatatype::IdRef),
5129		}
5130	}
5131	pub fn cloned(&self) -> NameValue {
5132		match *self {
5133			Self::Name(value) => NameValue::Name(value.to_owned()),
5134			Self::NCName(value) => NameValue::NCName(value.to_owned()),
5135			Self::Id(value) => NameValue::Id(value.to_owned()),
5136			Self::IdRef(value) => NameValue::IdRef(value.to_owned()),
5137		}
5138	}
5139}
5140impl<'a> XsdValue for NameValueRef<'a> {
5141	fn datatype(&self) -> Datatype {
5142		self.datatype().into()
5143	}
5144}
5145impl<'a> fmt::Display for NameValueRef<'a> {
5146	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5147		match self {
5148			Self::Name(v) => v.fmt(f),
5149			Self::NCName(v) => v.fmt(f),
5150			Self::Id(v) => v.fmt(f),
5151			Self::IdRef(v) => v.fmt(f),
5152		}
5153	}
5154}
5155impl<'a> From<NCNameValueRef<'a>> for NameValueRef<'a> {
5156	fn from(value: NCNameValueRef<'a>) -> Self {
5157		match value {
5158			NCNameValueRef::NCName(value) => Self::NCName(value),
5159			NCNameValueRef::Id(value) => Self::Id(value),
5160			NCNameValueRef::IdRef(value) => Self::IdRef(value),
5161		}
5162	}
5163}
5164impl<'a> TryFrom<NameValueRef<'a>> for NCNameValueRef<'a> {
5165	type Error = NameValueRef<'a>;
5166	fn try_from(value: NameValueRef<'a>) -> Result<Self, NameValueRef<'a>> {
5167		match value {
5168			NameValueRef::NCName(value) => Ok(Self::NCName(value)),
5169			NameValueRef::Id(value) => Ok(Self::Id(value)),
5170			NameValueRef::IdRef(value) => Ok(Self::IdRef(value)),
5171			other => Err(other),
5172		}
5173	}
5174}
5175/// Any specialized [`NCName`] value.
5176#[derive(Debug, Clone)]
5177pub enum NCNameValue {
5178	NCName(NCNameBuf),
5179	Id(IdBuf),
5180	IdRef(IdRefBuf),
5181}
5182impl NCNameValue {
5183	pub fn datatype(&self) -> NCNameDatatype {
5184		match self {
5185			Self::NCName(_) => NCNameDatatype::NCName,
5186			Self::Id(_) => NCNameDatatype::Id,
5187			Self::IdRef(_) => NCNameDatatype::IdRef,
5188		}
5189	}
5190}
5191impl XsdValue for NCNameValue {
5192	fn datatype(&self) -> Datatype {
5193		self.datatype().into()
5194	}
5195}
5196impl fmt::Display for NCNameValue {
5197	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5198		match self {
5199			Self::NCName(v) => v.fmt(f),
5200			Self::Id(v) => v.fmt(f),
5201			Self::IdRef(v) => v.fmt(f),
5202		}
5203	}
5204}
5205/// Any specialized [`NCName`] value reference.
5206#[derive(Debug, Clone, Copy)]
5207pub enum NCNameValueRef<'a> {
5208	NCName(&'a NCName),
5209	Id(&'a Id),
5210	IdRef(&'a IdRef),
5211}
5212impl NCNameValue {
5213	pub fn as_ref(&self) -> NCNameValueRef {
5214		match self {
5215			Self::NCName(value) => NCNameValueRef::NCName(value),
5216			Self::Id(value) => NCNameValueRef::Id(value),
5217			Self::IdRef(value) => NCNameValueRef::IdRef(value),
5218		}
5219	}
5220}
5221impl<'a> NCNameValueRef<'a> {
5222	pub fn datatype(&self) -> NCNameDatatype {
5223		match self {
5224			Self::NCName(_) => NCNameDatatype::NCName,
5225			Self::Id(_) => NCNameDatatype::Id,
5226			Self::IdRef(_) => NCNameDatatype::IdRef,
5227		}
5228	}
5229	pub fn cloned(&self) -> NCNameValue {
5230		match *self {
5231			Self::NCName(value) => NCNameValue::NCName(value.to_owned()),
5232			Self::Id(value) => NCNameValue::Id(value.to_owned()),
5233			Self::IdRef(value) => NCNameValue::IdRef(value.to_owned()),
5234		}
5235	}
5236}
5237impl<'a> XsdValue for NCNameValueRef<'a> {
5238	fn datatype(&self) -> Datatype {
5239		self.datatype().into()
5240	}
5241}
5242impl<'a> fmt::Display for NCNameValueRef<'a> {
5243	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5244		match self {
5245			Self::NCName(v) => v.fmt(f),
5246			Self::Id(v) => v.fmt(f),
5247			Self::IdRef(v) => v.fmt(f),
5248		}
5249	}
5250}
5251impl From<DurationDatatype> for Datatype {
5252	fn from(value: DurationDatatype) -> Self {
5253		Self::Duration(value)
5254	}
5255}
5256impl TryFrom<Datatype> for DurationDatatype {
5257	type Error = Datatype;
5258	fn try_from(value: Datatype) -> Result<Self, Datatype> {
5259		match value {
5260			Datatype::Duration(value) => Ok(value),
5261			other => Err(other),
5262		}
5263	}
5264}
5265impl From<DurationValue> for Value {
5266	fn from(value: DurationValue) -> Self {
5267		match value {
5268			DurationValue::Duration(value) => Self::Duration(value),
5269			DurationValue::DayTimeDuration(value) => Self::DayTimeDuration(value),
5270			DurationValue::YearMonthDuration(value) => Self::YearMonthDuration(value),
5271		}
5272	}
5273}
5274impl TryFrom<Value> for DurationValue {
5275	type Error = Value;
5276	fn try_from(value: Value) -> Result<Self, Value> {
5277		match value {
5278			Value::Duration(value) => Ok(Self::Duration(value)),
5279			Value::DayTimeDuration(value) => Ok(Self::DayTimeDuration(value)),
5280			Value::YearMonthDuration(value) => Ok(Self::YearMonthDuration(value)),
5281			other => Err(other),
5282		}
5283	}
5284}
5285/// Any specialized [`Duration`] value.
5286#[derive(Debug, Clone)]
5287pub enum DurationValue {
5288	Duration(Duration),
5289	DayTimeDuration(DayTimeDuration),
5290	YearMonthDuration(YearMonthDuration),
5291}
5292impl DurationValue {
5293	pub fn datatype(&self) -> DurationDatatype {
5294		match self {
5295			Self::Duration(_) => DurationDatatype::Duration,
5296			Self::DayTimeDuration(_) => DurationDatatype::DayTimeDuration,
5297			Self::YearMonthDuration(_) => DurationDatatype::YearMonthDuration,
5298		}
5299	}
5300}
5301impl XsdValue for DurationValue {
5302	fn datatype(&self) -> Datatype {
5303		self.datatype().into()
5304	}
5305}
5306impl fmt::Display for DurationValue {
5307	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5308		match self {
5309			Self::Duration(v) => v.fmt(f),
5310			Self::DayTimeDuration(v) => v.fmt(f),
5311			Self::YearMonthDuration(v) => v.fmt(f),
5312		}
5313	}
5314}
5315impl From<DateTimeDatatype> for Datatype {
5316	fn from(value: DateTimeDatatype) -> Self {
5317		Self::DateTime(value)
5318	}
5319}
5320impl TryFrom<Datatype> for DateTimeDatatype {
5321	type Error = Datatype;
5322	fn try_from(value: Datatype) -> Result<Self, Datatype> {
5323		match value {
5324			Datatype::DateTime(value) => Ok(value),
5325			other => Err(other),
5326		}
5327	}
5328}
5329impl From<DateTimeValue> for Value {
5330	fn from(value: DateTimeValue) -> Self {
5331		match value {
5332			DateTimeValue::DateTime(value) => Self::DateTime(value),
5333			DateTimeValue::DateTimeStamp(value) => Self::DateTimeStamp(value),
5334		}
5335	}
5336}
5337impl TryFrom<Value> for DateTimeValue {
5338	type Error = Value;
5339	fn try_from(value: Value) -> Result<Self, Value> {
5340		match value {
5341			Value::DateTime(value) => Ok(Self::DateTime(value)),
5342			Value::DateTimeStamp(value) => Ok(Self::DateTimeStamp(value)),
5343			other => Err(other),
5344		}
5345	}
5346}
5347/// Any specialized [`DateTime`] value.
5348#[derive(Debug, Clone)]
5349pub enum DateTimeValue {
5350	DateTime(DateTime),
5351	DateTimeStamp(DateTimeStamp),
5352}
5353impl DateTimeValue {
5354	pub fn datatype(&self) -> DateTimeDatatype {
5355		match self {
5356			Self::DateTime(_) => DateTimeDatatype::DateTime,
5357			Self::DateTimeStamp(_) => DateTimeDatatype::DateTimeStamp,
5358		}
5359	}
5360}
5361impl XsdValue for DateTimeValue {
5362	fn datatype(&self) -> Datatype {
5363		self.datatype().into()
5364	}
5365}
5366impl fmt::Display for DateTimeValue {
5367	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
5368		match self {
5369			Self::DateTime(v) => v.fmt(f),
5370			Self::DateTimeStamp(v) => v.fmt(f),
5371		}
5372	}
5373}