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
pub trait TryFromBytes<T>: Sized {
type Error;
fn try_from_bytes<I: IntoIterator<Item = T>>(bytes: I) -> Result<Self, Self::Error>;
}
pub(crate) trait TryConsumeBytes<I: Iterator<Item = u8>>: Sized {
type Error;
fn try_consume_bytes(bytes: &mut I) -> Result<Self, Self::Error>;
}
pub(crate) trait TryConsumeNBytes<I: Iterator<Item = u8>>: Sized {
type Error;
fn try_consume_n_bytes(n: usize, bytes: &mut I) -> Result<Self, Self::Error>;
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub enum OptParseError {
UnexpectedEndOfStream,
OptionValueTooLong { capacity: usize, actual: usize },
TooManyOptions(usize),
OptionDeltaReservedValue(u8),
ValueLengthReservedValue(u8),
OptionsExhausted,
}
impl OptParseError {
pub(super) fn try_next<I>(mut iter: impl Iterator<Item = I>) -> Result<I, Self> {
iter.next().ok_or(Self::UnexpectedEndOfStream)
}
}
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub enum MessageParseError {
UnexpectedEndOfStream,
InvalidTokenLength(u8),
OptParseError(OptParseError),
PayloadTooLong(usize),
}
impl MessageParseError {
pub(super) fn try_next<I>(iter: &mut impl Iterator<Item = I>) -> Result<I, Self> {
iter.next().ok_or(Self::UnexpectedEndOfStream)
}
}