retty_io/deprecated/
notify.rs

1use channel;
2use std::{any, error, fmt, io};
3
4pub enum NotifyError<T> {
5    Io(io::Error),
6    Full(T),
7    Closed(Option<T>),
8}
9
10impl<M> fmt::Debug for NotifyError<M> {
11    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
12        match *self {
13            NotifyError::Io(ref e) => {
14                write!(fmt, "NotifyError::Io({:?})", e)
15            }
16            NotifyError::Full(..) => {
17                write!(fmt, "NotifyError::Full(..)")
18            }
19            NotifyError::Closed(..) => {
20                write!(fmt, "NotifyError::Closed(..)")
21            }
22        }
23    }
24}
25
26impl<M> fmt::Display for NotifyError<M> {
27    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
28        match *self {
29            NotifyError::Io(ref e) => {
30                write!(fmt, "IO error: {}", e)
31            }
32            NotifyError::Full(..) => write!(fmt, "Full"),
33            NotifyError::Closed(..) => write!(fmt, "Closed"),
34        }
35    }
36}
37
38impl<M: any::Any> error::Error for NotifyError<M> {
39    fn description(&self) -> &str {
40        match *self {
41            NotifyError::Io(ref err) => err.description(),
42            NotifyError::Closed(..) => "The receiving end has hung up",
43            NotifyError::Full(..) => "Queue is full",
44        }
45    }
46
47    fn cause(&self) -> Option<&error::Error> {
48        match *self {
49            NotifyError::Io(ref err) => Some(err),
50            _ => None,
51        }
52    }
53}
54
55impl<M> From<channel::TrySendError<M>> for NotifyError<M> {
56    fn from(src: channel::TrySendError<M>) -> NotifyError<M> {
57        match src {
58            channel::TrySendError::Io(e) => NotifyError::Io(e),
59            channel::TrySendError::Full(v) => NotifyError::Full(v),
60            channel::TrySendError::Disconnected(v) => NotifyError::Closed(Some(v)),
61        }
62    }
63}