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
/// Enumerate the current poll state.
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub(crate) enum PollState {
    /// There is no associated future or stream.
    /// This can be because no item was placed to begin with, or because there
    /// are was previously an item but there no longer is.
    None,
    /// Polling the associated future or stream.
    Pending,
    /// Data has been written to the output structure, and is now ready to be
    /// read.
    Ready,
}

impl PollState {
    /// Returns `true` if the metadata is [`None`][Self::None].
    #[must_use]
    #[inline]
    #[allow(unused)]
    pub(crate) fn is_none(&self) -> bool {
        matches!(self, Self::None)
    }

    /// Returns `true` if the metadata is [`Pending`][Self::Pending].
    #[must_use]
    #[inline]
    pub(crate) fn is_pending(&self) -> bool {
        matches!(self, Self::Pending)
    }

    /// Returns `true` if the poll state is [`Ready`][Self::Ready].
    #[must_use]
    #[inline]
    pub(crate) fn is_ready(&self) -> bool {
        matches!(self, Self::Ready)
    }

    /// Sets the poll state to [`None`][Self::None].
    #[inline]
    pub(crate) fn set_none(&mut self) {
        *self = PollState::None;
    }

    /// Sets the poll state to [`Ready`][Self::Pending].
    #[inline]
    #[allow(unused)]
    pub(crate) fn set_pending(&mut self) {
        *self = PollState::Pending;
    }

    /// Sets the poll state to [`Ready`][Self::Ready].
    #[inline]
    pub(crate) fn set_ready(&mut self) {
        *self = PollState::Ready;
    }
}