pub trait ConnectedUdp {
type Error: Error;
// Required methods
async fn send(&mut self, data: &[u8]) -> Result<(), Self::Error>;
async fn receive_into(
&mut self,
buffer: &mut [u8],
) -> Result<usize, Self::Error>;
}
Expand description
This trait is implemented by UDP sockets.
The socket it represents is both bound (has a local IP address, port and interface) and connected (has a remote IP address and port).
The term “connected” here refers to the semantics of POSIX datagram sockets, through which datagrams
are sent and received without having a remote address per call. It does not imply any process
of establishing a connection (which is absent in UDP). While there is typically no POSIX
bind()
call in the creation of such sockets, these are implicitly bound to a suitable local
address at connect time.
Required Associated Types§
Required Methods§
Sourceasync fn send(&mut self, data: &[u8]) -> Result<(), Self::Error>
async fn send(&mut self, data: &[u8]) -> Result<(), Self::Error>
Send the provided data to the connected peer
Sourceasync fn receive_into(
&mut self,
buffer: &mut [u8],
) -> Result<usize, Self::Error>
async fn receive_into( &mut self, buffer: &mut [u8], ) -> Result<usize, Self::Error>
Receive a datagram into the provided buffer.
If the received datagram exceeds the buffer’s length, it is received regardless, and the remaining bytes are discarded. The full datagram size is still indicated in the result, allowing the recipient to detect that truncation.
§Compatibility note
This deviates from the sync/nb equivalent trait in that it describes the overflow behavior
(a possibility not considered there). The name deviates from the original receive()
to
make room for a version that is more zero-copy friendly.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.