c_ares_resolver/
error.rs

1use std::error;
2use std::fmt;
3use std::io;
4
5/// Error codes that the library might return.
6#[derive(Debug)]
7pub enum Error {
8    /// An `io::Error`.
9    Io(io::Error),
10
11    /// A `c_ares::Error`.
12    Ares(c_ares::Error),
13}
14
15impl fmt::Display for Error {
16    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
17        match *self {
18            Self::Io(ref err) => err.fmt(f),
19            Self::Ares(ref err) => err.fmt(f),
20        }
21    }
22}
23
24impl error::Error for Error {
25    fn source(&self) -> Option<&(dyn error::Error + 'static)> {
26        match *self {
27            Self::Io(ref err) => Some(err),
28            Self::Ares(ref err) => Some(err),
29        }
30    }
31}
32
33impl From<io::Error> for Error {
34    fn from(err: io::Error) -> Self {
35        Self::Io(err)
36    }
37}
38
39impl From<c_ares::Error> for Error {
40    fn from(err: c_ares::Error) -> Self {
41        Self::Ares(err)
42    }
43}