pub trait UdpTransport:
Send
+ Sync
+ Debug
+ Sized
+ 'static {
// Required methods
fn from_std(socket: UdpSocket) -> Result<Self>;
fn local_addr(&self) -> Result<SocketAddr>;
fn poll_recv_io<R>(
&self,
cx: &mut Context<'_>,
recv: impl FnMut(&Self) -> Result<R>,
) -> Poll<Result<R>>;
fn poll_writable(&self, cx: &mut Context<'_>) -> Poll<Result<()>>;
fn try_send_io<R>(&self, send: impl FnOnce(&Self) -> Result<R>) -> Result<R>;
// Provided methods
fn max_transmit_segments(&self) -> usize { ... }
fn max_receive_segments(&self) -> usize { ... }
fn may_fragment(&self) -> bool { ... }
}Expand description
Async UDP socket abstraction for QUIC transport.
Runtime adapters implement this for their platform’s async UDP type. QUIC library adapters (e.g. trillium-quinn) consume this to bridge to their own socket traits.
The poll_recv_io and try_send_io methods pass &Self to the
caller’s closure, allowing the caller to access platform-specific
traits (e.g. AsFd on unix, AsSocket on windows) without those
traits appearing in this trait’s definition.
Runtimes that do not support UDP can use () as their
UdpTransport type — it returns errors from all operations.
Required Methods§
Sourcefn from_std(socket: UdpSocket) -> Result<Self>
fn from_std(socket: UdpSocket) -> Result<Self>
Wrap a bound, non-blocking std UDP socket into this async type.
Sourcefn local_addr(&self) -> Result<SocketAddr>
fn local_addr(&self) -> Result<SocketAddr>
The local address this socket is bound to.
Sourcefn poll_recv_io<R>(
&self,
cx: &mut Context<'_>,
recv: impl FnMut(&Self) -> Result<R>,
) -> Poll<Result<R>>
fn poll_recv_io<R>( &self, cx: &mut Context<'_>, recv: impl FnMut(&Self) -> Result<R>, ) -> Poll<Result<R>>
Poll for read readiness, then attempt a receive operation.
When the socket is readable, calls recv with &self. If
recv returns ErrorKind::WouldBlock, the implementation
clears readiness and re-polls on the next call.
Sourcefn poll_writable(&self, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_writable(&self, cx: &mut Context<'_>) -> Poll<Result<()>>
Poll for write readiness without attempting any I/O.
Used by QUIC implementations that separate readiness polling from the send attempt (e.g. quinn’s multi-sender pattern).
Sourcefn try_send_io<R>(&self, send: impl FnOnce(&Self) -> Result<R>) -> Result<R>
fn try_send_io<R>(&self, send: impl FnOnce(&Self) -> Result<R>) -> Result<R>
Attempt a send operation, managing readiness state.
Calls send with &self. On ErrorKind::WouldBlock, the
implementation ensures the next poll_writable
call returns Poll::Pending.
Provided Methods§
Sourcefn max_transmit_segments(&self) -> usize
fn max_transmit_segments(&self) -> usize
Maximum number of datagrams to send in a single syscall (GSO).
Sourcefn max_receive_segments(&self) -> usize
fn max_receive_segments(&self) -> usize
Maximum number of datagrams to receive in a single syscall (GRO).
Sourcefn may_fragment(&self) -> bool
fn may_fragment(&self) -> bool
Whether outbound datagrams may be fragmented by the network layer.
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.