embedded_nal_async_xtra/stack/
raw.rs1pub trait RawSocket {
2 type Error: embedded_io_async::Error;
3
4 async fn send(&mut self, mac: Option<&[u8; 6]>, data: &[u8]) -> Result<(), Self::Error>;
5 async fn receive_into(&mut self, buffer: &mut [u8]) -> Result<(usize, [u8; 6]), Self::Error>;
6}
7
8impl<T> RawSocket for &mut T
9where
10 T: RawSocket,
11{
12 type Error = T::Error;
13
14 async fn send(&mut self, mac: Option<&[u8; 6]>, data: &[u8]) -> Result<(), Self::Error> {
15 (**self).send(mac, data).await
16 }
17
18 async fn receive_into(&mut self, buffer: &mut [u8]) -> Result<(usize, [u8; 6]), Self::Error> {
19 (**self).receive_into(buffer).await
20 }
21}
22
23pub trait RawStack {
24 type Error: embedded_io_async::Error;
25
26 type Socket: RawSocket<Error = Self::Error>;
27
28 async fn bind(&self, interface: u32) -> Result<Self::Socket, Self::Error>;
29}
30
31impl<T> RawStack for &T
32where
33 T: RawStack,
34{
35 type Error = T::Error;
36
37 type Socket = T::Socket;
38
39 async fn bind(&self, interface: u32) -> Result<Self::Socket, Self::Error> {
40 (*self).bind(interface).await
41 }
42}
43
44impl<T> RawStack for &mut T
45where
46 T: RawStack,
47{
48 type Error = T::Error;
49
50 type Socket = T::Socket;
51
52 async fn bind(&self, interface: u32) -> Result<Self::Socket, Self::Error> {
53 (**self).bind(interface).await
54 }
55}