1#![forbid(unsafe_code)]
2use core::fmt;
3use core::fmt::Debug;
4#[derive(Debug, PartialEq, Eq)]
6pub enum SendError {
7 Closed,
10 ReceiveClosed,
13}
14impl core::error::Error for SendError {}
15impl fmt::Display for SendError {
16 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17 fmt::Display::fmt(
18 match *self {
19 SendError::Closed => "send to a closed channel",
20 SendError::ReceiveClosed => "send to a half closed channel",
21 },
22 f,
23 )
24 }
25}
26
27#[derive(Debug, PartialEq, Eq)]
29pub enum SendErrorTimeout {
30 Closed,
33 ReceiveClosed,
36 Timeout,
38}
39impl core::error::Error for SendErrorTimeout {}
40impl fmt::Display for SendErrorTimeout {
41 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
42 fmt::Display::fmt(
43 match *self {
44 SendErrorTimeout::Closed => "send to a closed channel",
45 SendErrorTimeout::ReceiveClosed => "send to a half closed channel",
46 SendErrorTimeout::Timeout => "send timeout",
47 },
48 f,
49 )
50 }
51}
52
53#[derive(Debug, PartialEq, Eq)]
55pub enum ReceiveError {
56 Closed,
59 SendClosed,
62}
63impl core::error::Error for ReceiveError {}
64impl fmt::Display for ReceiveError {
65 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66 fmt::Display::fmt(
67 match *self {
68 ReceiveError::Closed => "receive from a closed channel",
69 ReceiveError::SendClosed => "receive from a half closed channel",
70 },
71 f,
72 )
73 }
74}
75
76#[derive(Debug, PartialEq, Eq)]
78pub enum ReceiveErrorTimeout {
79 Closed,
82 SendClosed,
85 Timeout,
87}
88impl core::error::Error for ReceiveErrorTimeout {}
89impl fmt::Display for ReceiveErrorTimeout {
90 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91 fmt::Display::fmt(
92 match *self {
93 ReceiveErrorTimeout::Closed => "receive from a closed channel",
94 ReceiveErrorTimeout::SendClosed => "receive from a half closed channel",
95 ReceiveErrorTimeout::Timeout => "receive timeout",
96 },
97 f,
98 )
99 }
100}
101
102#[derive(Debug, PartialEq, Eq)]
104pub struct CloseError();
105impl core::error::Error for CloseError {}
106impl fmt::Display for CloseError {
107 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
108 fmt::Display::fmt("channel is already closed", f)
109 }
110}