base_scheduler/
address_resolve_error.rs1use crate::AddressResolveErrorKind;
5use std::{fmt, io};
6
7#[derive(Debug)]
9pub struct AddressResolveError {
10 pub kind: AddressResolveErrorKind,
12 pub code: Option<i32>,
14 pub message: String,
16 pub system_error: Option<io::Error>,
18}
19
20impl fmt::Display for AddressResolveError {
21 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
22 self.message.fmt(formatter)
23 }
24}
25
26impl std::error::Error for AddressResolveError {
27 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
28 self.system_error.as_ref().map(|error| error as _)
29 }
30}
31
32impl From<AddressResolveError> for io::Error {
33 fn from(error: AddressResolveError) -> Self {
34 use AddressResolveErrorKind::*;
35 let kind = match error.kind {
36 TemporaryFailure => io::ErrorKind::WouldBlock,
37 NameNotFound | ServiceUnavailable => io::ErrorKind::NotFound,
38 InvalidHints => io::ErrorKind::InvalidInput,
39 OutOfMemory => io::ErrorKind::OutOfMemory,
40 System => error
41 .system_error
42 .as_ref()
43 .map_or(io::ErrorKind::Other, io::Error::kind),
44 PermanentFailure | Other => io::ErrorKind::Other,
45 };
46 Self::new(kind, error)
47 }
48}