1#![no_std]
2#![allow(stable_features)]
3#![allow(unknown_lints)]
4#![feature(async_fn_in_trait)]
5#![allow(async_fn_in_trait)]
6#![feature(impl_trait_projections)]
7#![feature(impl_trait_in_assoc_type)]
8
9use no_std_net::SocketAddr;
10
11pub trait TcpSplittableConnection {
12 type Error: embedded_io::Error;
13
14 type Read<'a>: embedded_io_async::Read<Error = Self::Error>
15 where
16 Self: 'a;
17 type Write<'a>: embedded_io_async::Write<Error = Self::Error>
18 where
19 Self: 'a;
20
21 async fn split(&mut self) -> Result<(Self::Read<'_>, Self::Write<'_>), Self::Error>;
22}
23
24impl<'t, T> TcpSplittableConnection for &'t mut T
25where
26 T: TcpSplittableConnection + 't,
27{
28 type Error = T::Error;
29
30 type Read<'a> = T::Read<'a> where Self: 'a;
31
32 type Write<'a> = T::Write<'a> where Self: 'a;
33
34 async fn split(&mut self) -> Result<(Self::Read<'_>, Self::Write<'_>), Self::Error> {
35 (**self).split().await
36 }
37}
38
39pub trait TcpListen {
40 type Error: embedded_io::Error;
41
42 type Acceptor<'m>: TcpAccept<Error = Self::Error>
43 where
44 Self: 'm;
45
46 async fn listen(&self, remote: SocketAddr) -> Result<Self::Acceptor<'_>, Self::Error>;
47}
48
49impl<T> TcpListen for &T
50where
51 T: TcpListen,
52{
53 type Error = T::Error;
54
55 type Acceptor<'m> = T::Acceptor<'m>
56 where Self: 'm;
57
58 async fn listen(&self, remote: SocketAddr) -> Result<Self::Acceptor<'_>, Self::Error> {
59 (*self).listen(remote).await
60 }
61}
62
63impl<T> TcpListen for &mut T
64where
65 T: TcpListen,
66{
67 type Error = T::Error;
68
69 type Acceptor<'m> = T::Acceptor<'m>
70 where Self: 'm;
71
72 async fn listen(&self, remote: SocketAddr) -> Result<Self::Acceptor<'_>, Self::Error> {
73 (**self).listen(remote).await
74 }
75}
76
77pub trait TcpAccept {
78 type Error: embedded_io::Error;
79
80 type Connection<'m>: embedded_io_async::Read<Error = Self::Error>
81 + embedded_io_async::Write<Error = Self::Error>
82 where
83 Self: 'm;
84
85 async fn accept(&self) -> Result<Self::Connection<'_>, Self::Error>;
86}
87
88impl<T> TcpAccept for &T
89where
90 T: TcpAccept,
91{
92 type Error = T::Error;
93
94 type Connection<'m> = T::Connection<'m>
95 where Self: 'm;
96
97 async fn accept(&self) -> Result<Self::Connection<'_>, Self::Error> {
98 (**self).accept().await
99 }
100}
101
102impl<T> TcpAccept for &mut T
103where
104 T: TcpAccept,
105{
106 type Error = T::Error;
107
108 type Connection<'m> = T::Connection<'m>
109 where Self: 'm;
110
111 async fn accept(&self) -> Result<Self::Connection<'_>, Self::Error> {
112 (**self).accept().await
113 }
114}