1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::error::Error as StdError;
use std::fmt::Debug;
use std::net::AddrParseError;
use std::str::Utf8Error;
use thiserror::Error;
#[cfg(feature = "dns-resolver")]
use crate::dns;
#[cfg(feature = "http-resolver")]
use crate::http;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
#[error("no or invalid IP address string found")]
Addr,
#[error("IP version not requested was returned")]
Version,
#[cfg(feature = "dns-resolver")]
#[cfg_attr(docsrs, doc(cfg(feature = "dns-resolver")))]
#[error("dns resolver: {0}")]
Dns(dns::Error),
#[cfg(feature = "http-resolver")]
#[cfg_attr(docsrs, doc(cfg(feature = "http-resolver")))]
#[error("http resolver: {0}")]
Http(http::Error),
#[error("other resolver: {0}")]
Other(Box<dyn StdError + Send + Sync + 'static>),
}
impl Error {
pub fn new<E>(error: E) -> Self
where
E: StdError + Send + Sync + 'static,
{
Self::Other(Box::new(error))
}
}
#[cfg(feature = "dns-resolver")]
impl From<dns::Error> for Error {
fn from(error: dns::Error) -> Self {
Self::Dns(error)
}
}
#[cfg(feature = "http-resolver")]
impl From<http::Error> for Error {
fn from(error: http::Error) -> Self {
Self::Http(error)
}
}
impl From<Utf8Error> for Error {
fn from(_: Utf8Error) -> Self {
Self::Addr
}
}
impl From<AddrParseError> for Error {
fn from(_: AddrParseError) -> Self {
Self::Addr
}
}