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 pub fn is_empty(&self) -> bool {
312 match self {
313 TryRecvError::Empty => true,
314 _ => false,
315 }
316 }
317
318 pub fn is_disconnected(&self) -> bool {
320 match self {
321 TryRecvError::Disconnected => true,
322 _ => false,
323 }
324 }
325}
326
327impl fmt::Display for RecvTimeoutError {
328 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
329 match *self {
330 RecvTimeoutError::Timeout => "timed out waiting on receive operation".fmt(f),
331 RecvTimeoutError::Disconnected => "channel is empty and disconnected".fmt(f),
332 }
333 }
334}
335
336impl error::Error for RecvTimeoutError {}
337
338impl From<RecvError> for RecvTimeoutError {
339 fn from(err: RecvError) -> RecvTimeoutError {
340 match err {
341 RecvError => RecvTimeoutError::Disconnected,
342 }
343 }
344}
345
346impl RecvTimeoutError {
347 pub fn is_timeout(&self) -> bool {
349 match self {
350 RecvTimeoutError::Timeout => true,
351 _ => false,
352 }
353 }
354
355 pub fn is_disconnected(&self) -> bool {
357 match self {
358 RecvTimeoutError::Disconnected => true,
359 _ => false,
360 }
361 }
362}
363
364impl fmt::Display for TrySelectError {
365 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
366 "all operations in select would block".fmt(f)
367 }
368}
369
370impl error::Error for TrySelectError {}
371
372impl fmt::Display for SelectTimeoutError {
373 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
374 "timed out waiting on select".fmt(f)
375 }
376}
377
378impl error::Error for SelectTimeoutError {}