generic_channel/
receiver.rs1#[cfg(feature = "crossbeam_channel")]
2mod crossbeam;
3mod standard;
4use std::{error, fmt};
5
6pub trait Receiver<T> {
7 fn try_recv(&self) -> Result<T, TryRecvError>;
8}
9
10#[derive(PartialEq, Eq, Clone, Copy, Debug)]
11pub enum TryRecvError {
12 Empty,
14 Disconnected,
16}
17
18impl fmt::Display for TryRecvError {
19 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20 match *self {
21 TryRecvError::Empty => "receiving on an empty channel".fmt(f),
22 TryRecvError::Disconnected => "receiving on a closed channel".fmt(f),
23 }
24 }
25}
26
27impl error::Error for TryRecvError {
28 fn description(&self) -> &str {
29 match *self {
30 TryRecvError::Empty => "receiving on an empty channel",
31 TryRecvError::Disconnected => "receiving on a closed channel",
32 }
33 }
34
35 fn cause(&self) -> Option<&dyn error::Error> {
36 None
37 }
38}