pub trait DatagramSocket: Sealed {
type Addr;
// Required methods
fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, Self::Addr)>;
fn send_to(&self, buf: &[u8], addr: &Self::Addr) -> Result<usize>;
}Available on crate feature
net only.Expand description
A message-oriented (datagram) socket: each recv_from yields exactly one whole message with
its sender, and each send_to writes one message to a peer. This is the datagram counterpart
to Read + Write (which std does ship but has no datagram analog of) — it makes a transport
usable with MessageDatagram.
Sealed: bnb implements it for UdpSocket, (on Unix) std::os::unix::net::UnixDatagram,
and — under the mock feature — MockDatagramSocket. Downstream crates can’t add their own
impls, so bnb keeps the freedom to evolve the trait; to test datagram code, use
MockDatagramSocket (the mock feature) or a loopback UdpSocket.
Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl DatagramSocket for UdpSocket
impl DatagramSocket for UdpSocket
Source§impl DatagramSocket for UnixDatagram
Available on Unix only.
impl DatagramSocket for UnixDatagram
Available on Unix only.
Implementors§
Source§impl DatagramSocket for MockDatagramSocket
Available on crate feature mock only.
impl DatagramSocket for MockDatagramSocket
Available on crate feature
mock only.