1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use core::fmt;

use crate::{
	lexical::{self, LexicalFormOf},
	Datatype, ParseXsd, XsdValue,
};

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Boolean(pub bool);

impl From<bool> for Boolean {
	fn from(value: bool) -> Self {
		Self(value)
	}
}

impl From<Boolean> for bool {
	fn from(value: Boolean) -> Self {
		value.0
	}
}

impl XsdValue for Boolean {
	fn datatype(&self) -> Datatype {
		Datatype::Boolean
	}
}

impl LexicalFormOf<Boolean> for lexical::Boolean {
	type ValueError = std::convert::Infallible;

	fn try_as_value(&self) -> Result<Boolean, Self::ValueError> {
		Ok(self.value())
	}
}

impl ParseXsd for Boolean {
	type LexicalForm = lexical::Boolean;
}

impl fmt::Display for Boolean {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		if self.0 {
			write!(f, "true")
		} else {
			write!(f, "false")
		}
	}
}