generic_channel/
sender.rs1#[cfg(feature = "crossbeam-channel")]
2mod crossbeam;
3#[cfg(feature = "futures")]
4mod futures;
5mod standard;
6
7use std::{error, fmt};
8
9pub trait Sender<T> {
10 fn try_send(&mut self, t: T) -> Result<(), TrySendError<T>>;
11}
12
13#[derive(PartialEq, Eq, Clone, Copy)]
14pub enum TrySendError<T> {
15 Full(T),
17 Disconnected(T),
19}
20
21impl<T> fmt::Debug for TrySendError<T> {
22 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
23 match *self {
24 TrySendError::Full(..) => "Full(..)".fmt(f),
25 TrySendError::Disconnected(..) => "Disconnected(..)".fmt(f),
26 }
27 }
28}
29
30impl<T> fmt::Display for TrySendError<T> {
31 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
32 match *self {
33 TrySendError::Full(..) => "sending on a full channel".fmt(f),
34 TrySendError::Disconnected(..) => "sending on a closed channel".fmt(f),
35 }
36 }
37}
38
39impl<T: Send> error::Error for TrySendError<T> {
40 fn description(&self) -> &str {
41 match *self {
42 TrySendError::Full(..) => "sending on a full channel",
43 TrySendError::Disconnected(..) => "sending on a closed channel",
44 }
45 }
46
47 fn cause(&self) -> Option<&dyn error::Error> {
48 None
49 }
50}