futures_intrusive/channel/
error.rs

1/// The error which is returned when sending a value into a channel fails.
2///
3/// The `send` operation can only fail if the channel has been closed, which
4/// would prevent the other actors to ever retrieve the value.
5///
6/// The error recovers the value that has been sent.
7#[derive(PartialEq, Debug)]
8pub struct ChannelSendError<T>(pub T);
9
10/// The error which is returned when trying to receive from a channel
11/// without waiting fails.
12#[derive(PartialEq, Debug, Copy, Clone)]
13pub enum TryReceiveError {
14    /// The channel is empty. No value is available for reception.
15    Empty,
16    /// The channel had been closed and no more value is available for reception.
17    Closed,
18}
19
20impl TryReceiveError {
21    /// Returns whether the error is the `Empty` variant.
22    pub fn is_empty(self) -> bool {
23        match self {
24            Self::Empty => true,
25            _ => false,
26        }
27    }
28
29    /// Returns whether the error is the `Closed` variant.
30    pub fn is_closed(self) -> bool {
31        match self {
32            Self::Closed => true,
33            _ => false,
34        }
35    }
36}
37
38/// The error which is returned when trying to send on a channel
39/// without waiting fails.
40#[derive(PartialEq, Debug)]
41pub enum TrySendError<T> {
42    /// The channel is full.
43    Full(T),
44    /// The channel was closed.
45    Closed(T),
46}
47
48impl<T> TrySendError<T> {
49    /// Converts the error into its inner value.
50    pub fn into_inner(self) -> T {
51        match self {
52            Self::Closed(inner) => inner,
53            Self::Full(inner) => inner,
54        }
55    }
56
57    /// Returns whether the error is the `WouldBlock` variant.
58    pub fn is_full(&self) -> bool {
59        match self {
60            Self::Full(_) => true,
61            _ => false,
62        }
63    }
64
65    /// Returns whether the error is the `Closed` variant.
66    pub fn is_closed(&self) -> bool {
67        match self {
68            Self::Closed(_) => true,
69            _ => false,
70        }
71    }
72}