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