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
use fd;
use std::io;
use Argdata;
use ReadError;
use Value;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Bool {
value: bool,
}
pub fn bool(value: bool) -> Bool {
Bool { value }
}
impl Bool {
pub fn value(&self) -> bool {
self.value
}
}
impl<'d> Argdata<'d> for Bool {
fn read<'a>(&'a self) -> Result<Value<'a, 'd>, ReadError>
where
'd: 'a,
{
Ok(Value::Bool(self.value))
}
fn serialized_length(&self) -> usize {
match self.value {
false => 1,
true => 2,
}
}
fn serialize(&self, writer: &mut io::Write, _: Option<&mut fd::FdMapping>) -> io::Result<()> {
match self.value {
false => writer.write_all(&[2]),
true => writer.write_all(&[2, 1]),
}
}
}