1extern crate tokio;
2
3use std::error::Error as StdError;
4use std::fmt;
5
6#[derive(Debug)]
7pub enum Error {
8 NotRunning,
9 MPSCRecv,
10 MPSCTrySend,
11 OneShotRecv,
12 OneShotSend,
13}
14
15impl StdError for Error {
16 fn description(&self) -> &str {
17 match self {
18 Error::NotRunning => "run() must be called first",
19 Error::MPSCRecv => "mpsc recieve failed",
20 Error::MPSCTrySend => "mpsc `try_send()` failed",
21 Error::OneShotRecv => "oneshot receive failed",
22 Error::OneShotSend => "oneshot `send()` failed",
23 }
24 }
25}
26
27impl fmt::Display for Error {
28 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29 write!(f, "{}", self.description())
30 }
31}
32
33impl From<tokio::sync::mpsc::error::UnboundedRecvError> for Error {
34 fn from(_: tokio::sync::mpsc::error::UnboundedRecvError) -> Self {
35 Error::MPSCRecv
36 }
37}
38
39impl<T> From<tokio::sync::mpsc::error::UnboundedTrySendError<T>> for Error {
40 fn from(_: tokio::sync::mpsc::error::UnboundedTrySendError<T>) -> Self {
41 Error::MPSCTrySend
42 }
43}
44
45impl From<tokio::sync::oneshot::error::RecvError> for Error {
46 fn from(_: tokio::sync::oneshot::error::RecvError) -> Self {
47 Error::OneShotRecv
48 }
49}