channel_receiver/
error.rs1#[derive(Debug, Eq)]
3pub enum TryRecvError {
4 Empty,
5 Closed,
6 Disconnected,
7}
8impl core::fmt::Display for TryRecvError {
9 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
10 write!(f, "{self:?}")
11 }
12}
13impl std::error::Error for TryRecvError {}
14impl core::cmp::PartialEq for TryRecvError {
15 fn eq(&self, other: &Self) -> bool {
16 matches!(
17 (self, other),
18 (Self::Empty, Self::Empty)
19 | (Self::Closed, Self::Closed)
20 | (Self::Closed, Self::Disconnected)
21 | (Self::Disconnected, Self::Disconnected)
22 | (Self::Disconnected, Self::Closed)
23 )
24 }
25}
26
27impl TryRecvError {
28 pub fn is_empty(&self) -> bool {
29 matches!(self, Self::Empty)
30 }
31
32 pub fn is_closed_or_disconnected(&self) -> bool {
33 matches!(self, Self::Closed | Self::Disconnected)
34 }
35}
36
37#[derive(Debug, PartialEq, Eq)]
39pub enum OneshotRecvError {
40 Dropped,
41}
42impl core::fmt::Display for OneshotRecvError {
43 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44 write!(f, "{self:?}")
45 }
46}
47impl std::error::Error for OneshotRecvError {}
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_try_recv_error_partial_eq() {
55 assert_eq!(TryRecvError::Empty, TryRecvError::Empty);
56 assert_eq!(TryRecvError::Closed, TryRecvError::Closed);
57 assert_eq!(TryRecvError::Closed, TryRecvError::Disconnected);
58 assert_eq!(TryRecvError::Disconnected, TryRecvError::Disconnected);
59 assert_ne!(TryRecvError::Empty, TryRecvError::Closed);
60 assert_ne!(TryRecvError::Empty, TryRecvError::Disconnected);
61 }
62}