1#![forbid(unsafe_code)]
2use core::{fmt, fmt::Debug};
3
4#[derive(PartialEq, Eq, Clone, Copy)]
6pub struct SendError<T>(pub T);
7
8impl<T> Debug for SendError<T> {
9 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10 write!(f, "SendError(..)")
11 }
12}
13impl<T> fmt::Display for SendError<T> {
14 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
15 fmt::Display::fmt("send to a closed channel", f)
16 }
17}
18
19impl<T> SendError<T> {
20 #[inline]
22 pub fn into_inner(self) -> T {
23 self.0
24 }
25}
26
27impl<T> std::error::Error for SendError<T> {}
28
29#[derive(PartialEq, Eq, Clone, Copy)]
31pub enum SendTimeoutError<T> {
32 Closed(T),
35 Timeout(T),
37}
38
39impl<T> Debug for SendTimeoutError<T> {
40 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
41 match self {
42 SendTimeoutError::Closed(..) => write!(f, "Closed(..)"),
43 SendTimeoutError::Timeout(..) => write!(f, "Timeout(..)"),
44 }
45 }
46}
47impl<T> fmt::Display for SendTimeoutError<T> {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 fmt::Display::fmt(
50 match *self {
51 SendTimeoutError::Closed(..) => "send to a closed channel",
52 SendTimeoutError::Timeout(..) => "send timeout",
53 },
54 f,
55 )
56 }
57}
58
59impl<T> SendTimeoutError<T> {
60 #[inline]
62 pub fn into_inner(self) -> T {
63 match self {
64 SendTimeoutError::Closed(value) => value,
65 SendTimeoutError::Timeout(value) => value,
66 }
67 }
68}
69
70impl<T> std::error::Error for SendTimeoutError<T> {}
71
72#[derive(Debug, PartialEq, Eq)]
74pub struct ReceiveError();
75impl core::error::Error for ReceiveError {}
76impl fmt::Display for ReceiveError {
77 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
78 fmt::Display::fmt("receive from a closed channel", f)
79 }
80}
81
82#[derive(Debug, PartialEq, Eq)]
84pub enum ReceiveErrorTimeout {
85 Closed,
88 Timeout,
90}
91impl core::error::Error for ReceiveErrorTimeout {}
92impl fmt::Display for ReceiveErrorTimeout {
93 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94 fmt::Display::fmt(
95 match *self {
96 ReceiveErrorTimeout::Closed => "receive from a closed channel",
97 ReceiveErrorTimeout::Timeout => "receive timeout",
98 },
99 f,
100 )
101 }
102}
103
104#[derive(Debug, PartialEq, Eq)]
106pub struct CloseError();
107impl std::error::Error for CloseError {}
108impl fmt::Display for CloseError {
109 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
110 fmt::Display::fmt("channel is already closed", f)
111 }
112}