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