layered_io/
status.rs

1/// What is known about a stream in the future.
2#[derive(Copy, Clone, Eq, PartialEq, Debug)]
3pub enum Status {
4    /// The stream is open.
5    Open(Activity),
6
7    /// The stream has ended. No more bytes will be transmitted.
8    End,
9}
10
11impl Status {
12    /// Return `Status::Open` with activity state `Active`.
13    #[inline]
14    pub fn active() -> Self {
15        Self::Open(Activity::Active)
16    }
17
18    /// Return `Status::Open` with activity state `Push`.
19    #[inline]
20    pub fn push() -> Self {
21        Self::Open(Activity::Push)
22    }
23
24    /// Shorthand for testing equality with `Status::End`.
25    #[inline]
26    pub fn is_end(self) -> bool {
27        self == Self::End
28    }
29
30    /// Shorthand for testing equality with `Status::Open(Activity::Push)`.
31    #[inline]
32    pub fn is_push(self) -> bool {
33        self == Self::Open(Activity::Push)
34    }
35}
36
37/// For interactivity, it's desirable to avoid buffering data which is complete
38/// enough to be actionable. `Activity` allows writers to notify the API at
39/// points when the data provided is actionable and buffers should be flushed
40/// to the reader.
41///
42/// Users that aren't implementing buffering can ignore this.
43#[derive(Copy, Clone, Eq, PartialEq, Debug)]
44pub enum Activity {
45    /// The writer is actively writing and data may be buffered.
46    Active,
47
48    /// The writer has finished writing something actionable and requested
49    /// buffering layers flush at this point.
50    ///
51    /// This is similar to the [`PSH` flag] in TCP.
52    ///
53    /// [`PSH` flag]: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_segment_structure
54    Push,
55}