Trait embedded_nal_async::UdpClientStack
source · [−]pub trait UdpClientStack {
type UdpSocket;
type Error: Debug;
type SocketFuture<'m>: Future<Output = Result<Self::UdpSocket, Self::Error>> + 'm
where
Self: 'm;
type ConnectFuture<'m>: Future<Output = Result<(), Self::Error>> + 'm
where
Self: 'm;
type SendFuture<'m>: Future<Output = Result<(), Self::Error>> + 'm
where
Self: 'm;
type ReceiveFuture<'m>: Future<Output = Result<(usize, SocketAddr), Self::Error>> + 'm
where
Self: 'm;
type CloseFuture<'m>: Future<Output = Result<(), Self::Error>> + 'm
where
Self: 'm;
fn socket<'m>(&'m mut self) -> Self::SocketFuture<'m>;
fn connect<'m>(
&'m mut self,
socket: &'m mut Self::UdpSocket,
remote: SocketAddr
) -> Self::ConnectFuture<'m>;
fn send<'m>(
&'m mut self,
socket: &'m mut Self::UdpSocket,
buffer: &'m [u8]
) -> Self::SendFuture<'m>;
fn receive<'m>(
&'m mut self,
socket: &'m mut Self::UdpSocket,
buffer: &'m mut [u8]
) -> Self::ReceiveFuture<'m>;
fn close<'m>(&'m mut self, socket: Self::UdpSocket) -> Self::CloseFuture<'m>;
}Expand description
This trait is implemented by UDP/IP stacks. You could, for example, have
an implementation which knows how to send AT commands to an ESP8266 WiFi
module. You could have another implementation which knows how to driver the
Rust Standard Library’s std::net module. Given this trait, you can how
write a portable CoAP client which can work with either implementation.
Required Associated Types
Future returned by socket function.
Future returned by connect function.
Future returned by send function.
type ReceiveFuture<'m>: Future<Output = Result<(usize, SocketAddr), Self::Error>> + 'm
where
Self: 'm
type ReceiveFuture<'m>: Future<Output = Result<(usize, SocketAddr), Self::Error>> + 'm
where
Self: 'm
Future returned by receive function.
Required Methods
fn socket<'m>(&'m mut self) -> Self::SocketFuture<'m>
fn socket<'m>(&'m mut self) -> Self::SocketFuture<'m>
Open a socket for usage as a UDP client.
Returns Ok(socket) if the socket was successfully created.
fn connect<'m>(
&'m mut self,
socket: &'m mut Self::UdpSocket,
remote: SocketAddr
) -> Self::ConnectFuture<'m>
fn connect<'m>(
&'m mut self,
socket: &'m mut Self::UdpSocket,
remote: SocketAddr
) -> Self::ConnectFuture<'m>
Connect a UDP socket with a peer using a dynamically selected port.
Selects a port number automatically and initializes for read/writing.
Send a datagram to the remote host.
The remote host used is either the one specified in UdpStack::connect
or the last one used in UdpServerStack::write_to.
Read a datagram the remote host has sent to us.
Returns Ok((n, remote)), which means a datagram of size n has been
received from remote and been placed in &buffer[0..n], or an error.
If a packet has not been received when called, then [nb::Error::WouldBlock]
should be returned.
fn close<'m>(&'m mut self, socket: Self::UdpSocket) -> Self::CloseFuture<'m>
fn close<'m>(&'m mut self, socket: Self::UdpSocket) -> Self::CloseFuture<'m>
Close an existing UDP socket.