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
50
51
52
use std::fmt;
use serde::de;
use serde::de::{Deserialize, Deserializer, Unexpected, Visitor};
use serde::ser::{Serialize, Serializer};
pub type Integer = i64;
pub type Float = f32;
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct True;
impl<'de> Deserialize<'de> for True {
fn deserialize<D>(deserializer: D) -> Result<True, D::Error>
where
D: Deserializer<'de>,
{
struct TrueVisitor;
impl<'de> Visitor<'de> for TrueVisitor {
type Value = True;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("true")
}
fn visit_bool<E>(self, value: bool) -> Result<True, E>
where
E: de::Error,
{
match value {
true => Ok(True),
false => Err(E::invalid_value(Unexpected::Bool(value), &self)),
}
}
}
deserializer.deserialize_bool(TrueVisitor)
}
}
impl Serialize for True {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_bool(true)
}
}