Skip to content

Commit

Permalink
Implement Dns for &T where T: Dns
Browse files Browse the repository at this point in the history
  • Loading branch information
rmja committed May 28, 2023
1 parent cb280e5 commit a50a49b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions embedded-nal-async/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- Let `&T` for `T: Dns` implement `Dns`

## [0.4.0] - 2023-01-27

- Add traits for UDP
Expand Down
16 changes: 16 additions & 0 deletions embedded-nal-async/src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,19 @@ pub trait Dns {
/// [`rfc1035`]: https://tools.ietf.org/html/rfc1035
async fn get_host_by_address(&self, addr: IpAddr) -> Result<String<256>, Self::Error>;
}

impl<T: Dns> Dns for &T {
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<String<256>, Self::Error> {
T::get_host_by_address(self, addr).await
}
}

0 comments on commit a50a49b

Please sign in to comment.