rotor_stream/
intention.rs1use std::error::Error;
2
3use rotor::Time;
4
5
6use {Expectation, Intent, IntentBuilder};
7
8impl<M> Intent<M> {
9 pub fn of(machine: M) -> IntentBuilder<M> {
11 IntentBuilder(machine)
12 }
13 pub fn done() -> Self {
15 Intent(Err(None), Expectation::Sleep, None)
16 }
17 pub fn error(e: Box<Error>) -> Self {
19 Intent(Err(Some(e)), Expectation::Sleep, None)
20 }
21 pub fn deadline(self, deadline: Time) -> Intent<M> {
26 Intent(self.0, self.1, Some(deadline))
27 }
28 pub fn deadline_opt(self, deadline: Option<Time>) -> Intent<M> {
32 Intent(self.0, self.1, deadline)
33 }
34}
35
36impl<M> IntentBuilder<M> {
37 pub fn expect_bytes(self, min_bytes: usize) -> Intent<M> {
38 Intent(Ok(self.0), Expectation::Bytes(min_bytes), None)
39 }
40 pub fn expect_delimiter(self, delim: &'static [u8], max_bytes: usize)
41 -> Intent<M>
42 {
43 Intent(Ok(self.0),
44 Expectation::Delimiter(0, delim, max_bytes), None)
45 }
46 pub fn expect_delimiter_after(self, offset: usize,
47 delim: &'static [u8], max_bytes: usize)
48 -> Intent<M>
49 {
50 Intent(Ok(self.0),
51 Expectation::Delimiter(offset, delim, max_bytes), None)
52 }
53 pub fn expect_flush(self) -> Intent<M> {
54 Intent(Ok(self.0), Expectation::Flush(0), None)
55 }
56 pub fn expect(self, e: Expectation) -> Intent<M> {
61 Intent(Ok(self.0), e, None)
62 }
63 pub fn sleep(self) -> Intent<M> {
64 Intent(Ok(self.0), Expectation::Sleep, None)
65 }
66}