use core::net::IpAddr;
#[derive(Clone, Debug, PartialEq)]
pub enum AddrType {
IPv4,
IPv6,
Either,
}
pub trait Dns {
type Error: core::fmt::Debug;
fn get_host_by_name(
&mut self,
hostname: &str,
addr_type: AddrType,
) -> nb::Result<IpAddr, Self::Error>;
fn get_host_by_address(
&mut self,
addr: IpAddr,
result: &mut [u8],
) -> nb::Result<usize, Self::Error>;
}
impl<T: Dns> Dns for &mut T {
type Error = T::Error;
fn get_host_by_name(
&mut self,
hostname: &str,
addr_type: AddrType,
) -> nb::Result<IpAddr, Self::Error> {
T::get_host_by_name(self, hostname, addr_type)
}
fn get_host_by_address(
&mut self,
addr: IpAddr,
result: &mut [u8],
) -> nb::Result<usize, Self::Error> {
T::get_host_by_address(self, addr, result)
}
}