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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#![deny(missing_docs)]
mod arrays;
mod bool;
pub mod collections;
pub mod numbers;
mod wrappers;
use std::io::{Read, Write};
#[derive(Debug)]
pub enum WriteError {
Stream,
}
#[derive(Debug)]
pub enum ReadError {
Stream,
Invalid,
}
#[derive(Debug)]
pub enum Error {
Write(WriteError),
Read(ReadError),
}
impl From<WriteError> for Error {
fn from(error: WriteError) -> Error {
Error::Write(error)
}
}
impl From<ReadError> for Error {
fn from(error: ReadError) -> Error {
Error::Read(error)
}
}
pub trait ToStream<S> {
fn to_stream<W: Write>(&self, stream: &mut W) -> Result<(), WriteError>;
}
pub trait FromStream<S>: Sized {
fn from_stream<R: Read>(stream: &mut R) -> Result<Self, ReadError>;
}
#[inline(always)]
pub fn to_stream<S, V: ToStream<S>, W: Write>(value: &V, stream: &mut W) -> Result<(), WriteError> {
value.to_stream(stream)
}
#[inline(always)]
pub fn from_stream<S, V: FromStream<S>, R: Read>(stream: &mut R) -> Result<V, ReadError> {
V::from_stream(stream)
}
pub mod default_settings;