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
use std::error::Error;
use rotor::Time;
use {Expectation, Intent, IntentBuilder};
impl<M> Intent<M> {
pub fn of(machine: M) -> IntentBuilder<M> {
IntentBuilder(machine)
}
pub fn done() -> Self {
Intent(Err(None), Expectation::Sleep, None)
}
pub fn error(e: Box<Error>) -> Self {
Intent(Err(Some(e)), Expectation::Sleep, None)
}
pub fn deadline(self, deadline: Time) -> Intent<M> {
Intent(self.0, self.1, Some(deadline))
}
pub fn deadline_opt(self, deadline: Option<Time>) -> Intent<M> {
Intent(self.0, self.1, deadline)
}
}
impl<M> IntentBuilder<M> {
pub fn expect_bytes(self, min_bytes: usize) -> Intent<M> {
Intent(Ok(self.0), Expectation::Bytes(min_bytes), None)
}
pub fn expect_delimiter(self, delim: &'static [u8], max_bytes: usize)
-> Intent<M>
{
Intent(Ok(self.0),
Expectation::Delimiter(0, delim, max_bytes), None)
}
pub fn expect_delimiter_after(self, offset: usize,
delim: &'static [u8], max_bytes: usize)
-> Intent<M>
{
Intent(Ok(self.0),
Expectation::Delimiter(offset, delim, max_bytes), None)
}
pub fn expect_flush(self) -> Intent<M> {
Intent(Ok(self.0), Expectation::Flush(0), None)
}
pub fn expect(self, e: Expectation) -> Intent<M> {
Intent(Ok(self.0), e, None)
}
pub fn sleep(self) -> Intent<M> {
Intent(Ok(self.0), Expectation::Sleep, None)
}
}