tokio_resol_vbus/
error.rs

1use std::{error::Error as StdError, fmt};
2
3/// A common error type.
4#[derive(Debug, PartialEq)]
5pub struct Error {
6    description: String,
7}
8
9impl Error {
10    /// Construct a new `Error` using the provided description.
11    pub fn new<T: fmt::Display>(description: T) -> Error {
12        Error {
13            description: format!("{}", description),
14        }
15    }
16}
17
18impl fmt::Display for Error {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        write!(f, "{}", self.description)
21    }
22}
23
24impl StdError for Error {}
25
26macro_rules! from_other_error {
27    ($type:path) => {
28        impl From<$type> for Error {
29            fn from(cause: $type) -> Error {
30                Error::new(cause)
31            }
32        }
33    };
34}
35
36from_other_error!(std::io::Error);
37from_other_error!(std::net::AddrParseError);
38from_other_error!(std::str::Utf8Error);
39from_other_error!(resol_vbus::Error);
40from_other_error!(tokio::timer::Error);
41
42/// A common result type.
43pub type Result<T> = std::result::Result<T, Error>;