Added UDP Server Trait by jonahd-g · Pull Request #21 · rust-embedded-community/embedded-nal (original) (raw)

I don't know if it could make sense to split both traits into a core and a server trait, where the server trait could be considered optional?

pub trait UdpCore { /// The type returned when we create a new UDP socket type UdpSocket; /// The type returned when we have an error type Error: core::fmt::Debug;

fn open(&self, remote: SocketAddr, mode: Mode) -> Result<Self::UdpSocket, Self::Error>;

fn write(&self, socket: &mut Self::UdpSocket, buffer: &[u8]) -> nb::Result<(), Self::Error>;

fn read(
    &self,
    socket: &mut Self::UdpSocket,
    buffer: &mut [u8],
) -> nb::Result<(usize, SocketAddr), Self::Error>;

fn close(&self, socket: Self::UdpSocket) -> Result<(), Self::Error>;

}

pub trait UdpServer: UdpCore { fn bind(&self, socket: ::UdpSocket, local_port: u16) -> Result<(), ::Error>;

.... More UDP server functions? eg. sendto ?

}

It might look like its very few functions in the UDP case, but its a few more in TCP (accept, listen, bind...)