Skip to content

Commit 6f5dda9

Browse files
Dirbaioeldruin
authored andcommitted
async/tcp: switch to async-fn-in-trait
1 parent c33ae09 commit 6f5dda9

File tree

4 files changed

+20
-31
lines changed

4 files changed

+20
-31
lines changed

embedded-nal-async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ categories = ["embedded", "hardware-support", "no-std", "network-programming", "
1818
no-std-net = "0.6"
1919
heapless = "^0.7"
2020
embedded-nal = { version = "0.6.0", path = "../" }
21-
embedded-io = { version = "0.3.0", default-features = false, features = ["async"] }
21+
embedded-io = { version = "0.4.0", default-features = false, features = ["async"] }

embedded-nal-async/src/dns.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use core::future::Future;
21
use embedded_nal::AddrType;
32
use heapless::String;
43
use no_std_net::IpAddr;
@@ -17,29 +16,19 @@ pub trait Dns {
1716
/// The type returned when we have an error
1817
type Error: core::fmt::Debug;
1918

20-
/// Future for get_host_by_name
21-
type GetHostByNameFuture<'m>: Future<Output = Result<IpAddr, Self::Error>>
22-
where
23-
Self: 'm;
24-
2519
/// Resolve the first ip address of a host, given its hostname and a desired
2620
/// address record type to look for
27-
fn get_host_by_name<'m>(
28-
&'m self,
29-
host: &'m str,
21+
async fn get_host_by_name<'m>(
22+
&self,
23+
host: &str,
3024
addr_type: AddrType,
31-
) -> Self::GetHostByNameFuture<'m>;
32-
33-
/// Future for get_host_by_address
34-
type GetHostByAddressFuture<'m>: Future<Output = Result<String<256>, Self::Error>>
35-
where
36-
Self: 'm;
25+
) -> Result<IpAddr, Self::Error>;
3726

3827
/// Resolve the hostname of a host, given its ip address
3928
///
4029
/// **Note**: A fully qualified domain name (FQDN), has a maximum length of
4130
/// 255 bytes [`rfc1035`]
4231
///
4332
/// [`rfc1035`]: https://tools.ietf.org/html/rfc1035
44-
fn get_host_by_address<'m>(&'m self, addr: IpAddr) -> Self::GetHostByAddressFuture<'m>;
33+
async fn get_host_by_address(&self, addr: IpAddr) -> Result<String<256>, Self::Error>;
4534
}

embedded-nal-async/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! # embedded-nal-async - An async Network Abstraction Layer for Embedded Systems
22
33
#![no_std]
4-
#![feature(generic_associated_types)]
4+
#![feature(async_fn_in_trait, impl_trait_projections)]
5+
#![allow(incomplete_features)]
56
#![deny(missing_docs)]
67
#![deny(unsafe_code)]
78

embedded-nal-async/src/stack/tcp.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use core::future::Future;
21
use no_std_net::SocketAddr;
32

43
/// This trait is implemented by TCP/IP stacks. The trait allows the underlying driver to
@@ -10,29 +9,29 @@ pub trait TcpConnect {
109
type Error: embedded_io::Error;
1110

1211
/// Type holding state of a TCP connection. Should close the connection when dropped.
13-
type Connection<'m>: embedded_io::asynch::Read<Error = Self::Error>
12+
type Connection<'a>: embedded_io::asynch::Read<Error = Self::Error>
1413
+ embedded_io::asynch::Write<Error = Self::Error>
1514
where
16-
Self: 'm;
17-
/// Future returned by `connect` function.
18-
type ConnectFuture<'m>: Future<Output = Result<Self::Connection<'m>, Self::Error>> + 'm
19-
where
20-
Self: 'm;
15+
Self: 'a;
2116

2217
/// Connect to the given remote host and port.
2318
///
2419
/// Returns `Ok` if the connection was successful.
25-
fn connect<'m>(&'m self, remote: SocketAddr) -> Self::ConnectFuture<'m>;
20+
async fn connect<'a>(&'a self, remote: SocketAddr) -> Result<Self::Connection<'a>, Self::Error>
21+
// This bound is required due to an AFIT limitaton: https://github.com/rust-lang/rust/issues/104908
22+
where
23+
Self: 'a;
2624
}
2725

2826
impl<T: TcpConnect> TcpConnect for &T {
2927
type Error = T::Error;
3028

31-
type Connection<'m> = T::Connection<'m> where Self: 'm;
29+
type Connection<'a> = T::Connection<'a> where Self: 'a;
3230

33-
type ConnectFuture<'m> = T::ConnectFuture<'m> where Self: 'm;
34-
35-
fn connect<'m>(&'m self, remote: SocketAddr) -> Self::ConnectFuture<'m> {
36-
T::connect(self, remote)
31+
async fn connect<'a>(&'a self, remote: SocketAddr) -> Result<Self::Connection<'a>, Self::Error>
32+
where
33+
Self: 'a,
34+
{
35+
T::connect(self, remote).await
3736
}
3837
}

0 commit comments

Comments
 (0)