Skip to content

Commit 65ba5a3

Browse files
authored
Merge pull request #93 from Dirbaio/no-heapless
async: Do not use heapless on public API.
2 parents e0492ef + fb218be commit 65ba5a3

File tree

8 files changed

+31
-22
lines changed

8 files changed

+31
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
- Bump MSRV to 1.60.0 (required for Edition 2021)
1111
- Switch to Edition 2021
12+
- [breaking] `Dns::get_host_by_address` now uses `&mut [u8]` instead of `heapless::String`.
1213

1314
## [0.7.0] - 2023-06-21
1415

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ ip_in_core = []
2323

2424
[dependencies]
2525
nb = "1"
26-
no-std-net = { version = "0.6", optional = true }
27-
heapless = "^0.7"
26+
no-std-net = { version = "0.6", optional = true }

embedded-nal-async/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10-
No unreleased changes yet.
10+
- [breaking] `Dns::get_host_by_address` now uses `&mut [u8]` instead of `heapless::String`.
1111

1212
## [0.6.0] - 2023-10-03
1313

embedded-nal-async/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ ip_in_core = []
1616

1717
[dependencies]
1818
no-std-net = "0.6"
19-
heapless = "^0.7"
2019
embedded-nal = { version = "0.7.0", path = "../" }
2120
embedded-io-async = { version = "0.6.0" }

embedded-nal-async/src/dns.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::IpAddr;
22
use embedded_nal::AddrType;
3-
use heapless::String;
43

54
/// This trait is an extension trait for [`TcpStack`] and [`UdpStack`] for dns
65
/// resolutions. It does not handle every DNS record type, but is meant as an
@@ -24,13 +23,22 @@ pub trait Dns {
2423
addr_type: AddrType,
2524
) -> Result<IpAddr, Self::Error>;
2625

27-
/// Resolve the hostname of a host, given its ip address
26+
/// Resolve the hostname of a host, given its ip address.
27+
///
28+
/// The hostname is stored at the beginning of `result`, the length is returned.
29+
///
30+
/// If the buffer is too small to hold the domain name, an error should be returned.
2831
///
2932
/// **Note**: A fully qualified domain name (FQDN), has a maximum length of
30-
/// 255 bytes [`rfc1035`]
33+
/// 255 bytes according to [`rfc1035`]. Therefore, you can pass a 255-byte long
34+
/// buffer to guarantee it'll always be large enough.
3135
///
3236
/// [`rfc1035`]: https://tools.ietf.org/html/rfc1035
33-
async fn get_host_by_address(&self, addr: IpAddr) -> Result<String<256>, Self::Error>;
37+
async fn get_host_by_address(
38+
&self,
39+
addr: IpAddr,
40+
result: &mut [u8],
41+
) -> Result<usize, Self::Error>;
3442
}
3543

3644
impl<T: Dns> Dns for &T {
@@ -44,7 +52,11 @@ impl<T: Dns> Dns for &T {
4452
T::get_host_by_name(self, host, addr_type).await
4553
}
4654

47-
async fn get_host_by_address(&self, addr: IpAddr) -> Result<String<256>, Self::Error> {
48-
T::get_host_by_address(self, addr).await
55+
async fn get_host_by_address(
56+
&self,
57+
addr: IpAddr,
58+
result: &mut [u8],
59+
) -> Result<usize, Self::Error> {
60+
T::get_host_by_address(self, addr, result).await
4961
}
5062
}

embedded-nal-async/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
mod dns;
1111
mod stack;
12-
// Needed by embedded-nal trait implementers who build get_host_by_address results, or by trait
13-
// users who pass the results on.
14-
pub use heapless;
1512

1613
#[cfg(feature = "ip_in_core")]
1714
pub use core::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};

src/dns.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::IpAddr;
2-
use heapless::String;
32

43
/// This is the host address type to be returned by `gethostbyname`.
54
///
@@ -37,13 +36,18 @@ pub trait Dns {
3736
addr_type: AddrType,
3837
) -> nb::Result<IpAddr, Self::Error>;
3938

40-
/// Resolve the hostname of a host, given its ip address
39+
/// Resolve the hostname of a host, given its ip address.
40+
///
41+
/// The hostname is stored at the beginning of `result`, the length is returned.
42+
///
43+
/// If the buffer is too small to hold the domain name, an error should be returned.
4144
///
4245
/// **Note**: A fully qualified domain name (FQDN), has a maximum length of
43-
/// 255 bytes [`rfc1035`]
46+
/// 255 bytes according to [`rfc1035`]. Therefore, you can pass a 255-byte long
47+
/// buffer to guarantee it'll always be large enough.
4448
///
4549
/// [`rfc1035`]: https://tools.ietf.org/html/rfc1035
46-
fn get_host_by_address(&mut self, addr: IpAddr) -> nb::Result<String<256>, Self::Error>;
50+
fn get_host_by_address(&self, addr: IpAddr, result: &mut [u8]) -> Result<usize, Self::Error>;
4751
}
4852

4953
impl<T: Dns> Dns for &mut T {
@@ -57,7 +61,7 @@ impl<T: Dns> Dns for &mut T {
5761
T::get_host_by_name(self, hostname, addr_type)
5862
}
5963

60-
fn get_host_by_address(&mut self, addr: IpAddr) -> nb::Result<String<256>, Self::Error> {
61-
T::get_host_by_address(self, addr)
64+
fn get_host_by_address(&self, addr: IpAddr, result: &mut [u8]) -> Result<usize, Self::Error> {
65+
T::get_host_by_address(self, addr, result)
6266
}
6367
}

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ mod dns;
88
mod stack;
99

1010
pub use nb;
11-
// Needed by embedded-nal trait implementers who build get_host_by_address results, or by trait
12-
// users who pass the results on.
13-
pub use heapless;
1411

1512
#[cfg(not(any(feature = "ip_in_core", feature = "no-std-net")))]
1613
compile_error!("You must select the ip_in_core feature or the no-std-net feature");

0 commit comments

Comments
 (0)