Trait AsyncReadOwned
pub trait AsyncReadOwned {
// Required method
fn poll_read_owned<B>(
&mut self,
cx: &mut Context<'_>,
slot: &mut BufSlot<B>,
) -> Poll<Result<usize, Error>>
where B: IoBufMut;
// Provided method
fn read_owned<B>(
&mut self,
buf: B,
) -> impl Future<Output = (Result<usize, Error>, B)> + Send
where B: IoBufMut,
Self: Send { ... }
}Expand description
Read bytes into an owned buffer, returning the buffer with the result.
The read overwrites from offset 0 and, on success, sets the initialized
length to the bytes read, so reusing a buffer without clearing it is safe.
Pass a buffer with capacity (e.g. Vec::with_capacity(n)), a zero-capacity
buffer has nowhere to read into. To accumulate on top of prior bytes instead,
read into buf.uninit() (a spare-view that appends).
Required Methods§
fn poll_read_owned<B>(
&mut self,
cx: &mut Context<'_>,
slot: &mut BufSlot<B>,
) -> Poll<Result<usize, Error>>where
B: IoBufMut,
fn poll_read_owned<B>(
&mut self,
cx: &mut Context<'_>,
slot: &mut BufSlot<B>,
) -> Poll<Result<usize, Error>>where
B: IoBufMut,
The primitive. Poll a read into the owned buffer in slot, returning
the bytes read (0 = EOF). The buffer is moved through the read op:
- readiness backend (tokio): take the buffer,
poll_readinto it from offset 0, put it back, the buffer sits inslotacrossPending. - completion backend (io_uring): take the buffer, submit the op (the
op-slab owns it,
slotleftInFlight), on the CQE return it filled.
Zero-copy on both, never lends a borrowed buffer to the kernel. Generic (so not object-safe), the dyn erasure boundaries add a concrete shim.
Pass a buffer with capacity, the read overwrites from offset 0 and sets the initialized length to the bytes read.
Provided Methods§
fn read_owned<B>(
&mut self,
buf: B,
) -> impl Future<Output = (Result<usize, Error>, B)> + Send
fn read_owned<B>( &mut self, buf: B, ) -> impl Future<Output = (Result<usize, Error>, B)> + Send
Derived async convenience over poll_read_owned:
move buf in, drive to completion, hand it back filled. Not a second
impl: every owned reader gets it for free, relays and read_exact_into
use it.
async fn read(buf) -> BufResult is the primitive completion runtimes
(compio / monoio) settled on. We keep it derived rather than primitive
because a manual Future::poll consumer (e.g. hyper’s connection core)
can’t drive an async fn without boxing its future, so poll_read_owned
stays the real primitive.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".