xsd_types/value/
boolean.rs1use core::fmt;
2
3use crate::{
4 lexical::{self, LexicalFormOf},
5 Datatype, ParseXsd, XsdValue,
6};
7
8#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
9pub struct Boolean(pub bool);
10
11impl From<bool> for Boolean {
12 fn from(value: bool) -> Self {
13 Self(value)
14 }
15}
16
17impl From<Boolean> for bool {
18 fn from(value: Boolean) -> Self {
19 value.0
20 }
21}
22
23impl XsdValue for Boolean {
24 fn datatype(&self) -> Datatype {
25 Datatype::Boolean
26 }
27}
28
29impl LexicalFormOf<Boolean> for lexical::Boolean {
30 type ValueError = std::convert::Infallible;
31
32 fn try_as_value(&self) -> Result<Boolean, Self::ValueError> {
33 Ok(self.value())
34 }
35}
36
37impl ParseXsd for Boolean {
38 type LexicalForm = lexical::Boolean;
39}
40
41impl fmt::Display for Boolean {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 if self.0 {
44 write!(f, "true")
45 } else {
46 write!(f, "false")
47 }
48 }
49}