1use std::error;
2use std::fmt;
3
4#[derive(PartialEq, Eq, Clone, Copy)]
12pub struct SendError<T>(pub T);
13
14#[derive(PartialEq, Eq, Clone, Copy)]
20pub enum TrySendError<T> {
21 Full(T),
26
27 Disconnected(T),
29}
30
31#[derive(PartialEq, Eq, Clone, Copy)]
37pub enum SendTimeoutError<T> {
38 Timeout(T),
43
44 Disconnected(T),
46}
47
48#[derive(PartialEq, Eq, Clone, Copy, Debug)]
54pub struct RecvError;
55
56#[derive(PartialEq, Eq, Clone, Copy, Debug)]
60pub enum TryRecvError {
61 Empty,
66
67 Disconnected,
69}
70
71#[derive(PartialEq, Eq, Clone, Copy, Debug)]
75pub enum RecvTimeoutError {
76 Timeout,
81
82 Disconnected,
84}
85
86#[derive(PartialEq, Eq, Clone, Copy, Debug)]
92pub struct TrySelectError;
93
94#[derive(PartialEq, Eq, Clone, Copy, Debug)]
100pub struct SelectTimeoutError;
101
102#[derive(PartialEq, Eq, Clone, Copy, Debug)]
108pub struct TryReadyError;
109
110#[derive(PartialEq, Eq, Clone, Copy, Debug)]
116pub struct ReadyTimeoutError;
117
118impl<T> fmt::Debug for SendError<T> {
119 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
120 "SendError(..)".fmt(f)
121 }
122}
123
124impl<T> fmt::Display for SendError<T> {
125 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
126 "sending on a disconnected channel".fmt(f)
127 }
128}
129
130impl<T: Send> error::Error for SendError<T> {}
131
132impl<T> SendError<T> {
133 pub fn into_inner(self) -> T {
148 self.0
149 }
150}
151
152impl<T> fmt::Debug for TrySendError<T> {
153 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
154 match *self {
155 TrySendError::Full(..) => "Full(..)".fmt(f),
156 TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f),
157 }
158 }
159}
160
161impl<T> fmt::Display for TrySendError<T> {
162 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
163 match *self {
164 TrySendError::Full(..) => "sending on a full channel".fmt(f),
165 TrySendError::Disconnected(..) => "sending on a disconnected channel".fmt(f),
166 }
167 }
168}
169
170impl<T: Send> error::Error for TrySendError<T> {}
171
172impl<T> From<SendError<T>> for TrySendError<T> {
173 fn from(err: SendError<T>) -> TrySendError<T> {
174 match err {
175 SendError(t) => TrySendError::Disconnected(t),
176 }
177 }
178}
179
180impl<T> TrySendError<T> {
181 pub fn into_inner(self) -> T {
195 match self {
196 TrySendError::Full(v) => v,
197 TrySendError::Disconnected(v) => v,
198 }
199 }
200
201 pub fn is_full(&self) -> bool {
203 match self {
204 TrySendError::Full(_) => true,
205 _ => false,
206 }
207 }
208
209 pub fn is_disconnected(&self) -> bool {
211 match self {
212 TrySendError::Disconnected(_) => true,
213 _ => false,
214 }
215 }
216}
217
218impl<T> fmt::Debug for SendTimeoutError<T> {
219 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
220 "SendTimeoutError(..)".fmt(f)
221 }
222}
223
224impl<T> fmt::Display for SendTimeoutError<T> {
225 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
226 match *self {
227 SendTimeoutError::Timeout(..) => "timed out waiting on send operation".fmt(f),
228 SendTimeoutError::Disconnected(..) => "sending on a disconnected channel".fmt(f),
229 }
230 }
231}
232
233impl<T: Send> error::Error for SendTimeoutError<T> {}
234
235impl<T> From<SendError<T>> for SendTimeoutError<T> {
236 fn from(err: SendError<T>) -> SendTimeoutError<T> {
237 match err {
238 SendError(e) => SendTimeoutError::Disconnected(e),
239 }
240 }
241}
242
243impl<T> SendTimeoutError<T> {
244 pub fn into_inner(self) -> T {
259 match self {
260 SendTimeoutError::Timeout(v) => v,
261 SendTimeoutError::Disconnected(v) => v,
262 }
263 }
264
265 pub fn is_timeout(&self) -> bool {
267 match self {
268 SendTimeoutError::Timeout(_) => true,
269 _ => false,
270 }
271 }
272
273 pub fn is_disconnected(&self) -> bool {
275 match self {
276 SendTimeoutError::Disconnected(_) => true,
277 _ => false,
278 }
279 }
280}
281
282impl fmt::Display for RecvError {
283 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
284 "receiving on an empty and disconnected channel".fmt(f)
285 }
286}
287
288impl error::Error for RecvError {}
289
290impl fmt::Display for TryRecvError {
291 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
292 match *self {
293 TryRecvError::Empty => "receiving on an empty channel".fmt(f),
294 TryRecvError::Disconnected => "receiving on an empty and disconnected channel".fmt(f),
295 }
296 }
297}
298
299impl error::Error for TryRecvError {}
300
301impl From<RecvError> for TryRecvError {
302 fn from(err: RecvError) -> TryRecvError {
303 match err {
304 RecvError => TryRecvError::Disconnected,
305 }
306 }
307}
308
309impl TryRecvError {
310 #[allow(clippy::trivially_copy_pass_by_ref)]
312 pub fn is_empty(&self) -> bool {
313 match self {
314 TryRecvError::Empty => true,
315 _ => false,
316 }
317 }
318
319 #[allow(clippy::trivially_copy_pass_by_ref)]
321 pub fn is_disconnected(&self) -> bool {
322 match self {
323 TryRecvError::Disconnected => true,
324 _ => false,
325 }
326 }
327}
328
329impl fmt::Display for RecvTimeoutError {
330 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
331 match *self {
332 RecvTimeoutError::Timeout => "timed out waiting on receive operation".fmt(f),
333 RecvTimeoutError::Disconnected => "channel is empty and disconnected".fmt(f),
334 }
335 }
336}
337
338impl error::Error for RecvTimeoutError {}
339
340impl From<RecvError> for RecvTimeoutError {
341 fn from(err: RecvError) -> RecvTimeoutError {
342 match err {
343 RecvError => RecvTimeoutError::Disconnected,
344 }
345 }
346}
347
348impl RecvTimeoutError {
349 #[allow(clippy::trivially_copy_pass_by_ref)]
351 pub fn is_timeout(&self) -> bool {
352 match self {
353 RecvTimeoutError::Timeout => true,
354 _ => false,
355 }
356 }
357
358 #[allow(clippy::trivially_copy_pass_by_ref)]
360 pub fn is_disconnected(&self) -> bool {
361 match self {
362 RecvTimeoutError::Disconnected => true,
363 _ => false,
364 }
365 }
366}
367
368impl fmt::Display for TrySelectError {
369 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
370 "all operations in select would block".fmt(f)
371 }
372}
373
374impl error::Error for TrySelectError {}
375
376impl fmt::Display for SelectTimeoutError {
377 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
378 "timed out waiting on select".fmt(f)
379 }
380}
381
382impl error::Error for SelectTimeoutError {}