1use fd;
2use std::io;
3use Argdata;
4use IntValue;
5use ReadError;
6use Value;
7
8#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
9pub struct Int<T> {
10 value: T,
11}
12
13pub fn int<T>(value: T) -> Int<T>
15where
16 T: Copy,
17 IntValue<'static>: From<T>,
18{
19 Int { value }
20}
21
22impl<T: Copy> Int<T> where {
23 pub fn value(&self) -> T {
24 self.value
25 }
26}
27
28impl<'d, T> Argdata<'d> for Int<T>
29where
30 T: Copy + Sync,
31 IntValue<'static>: From<T>,
32{
33 fn read<'a>(&'a self) -> Result<Value<'a, 'd>, ReadError>
34 where
35 'd: 'a,
36 {
37 Ok(Value::Int(IntValue::from(self.value)))
38 }
39
40 fn serialized_length(&self) -> usize {
41 IntValue::from(self.value).serialized_length() + 1
42 }
43
44 fn serialize(&self, writer: &mut io::Write, _: Option<&mut fd::FdMapping>) -> io::Result<()> {
45 writer.write_all(&[5])?;
46 IntValue::from(self.value).serialize(writer)
47 }
48}