Trait IoBuf
pub unsafe trait IoBuf: Send + 'static {
// Required method
fn as_init(&self) -> &[u8] ⓘ;
// Provided methods
fn buf_len(&self) -> usize { ... }
fn buf_ptr(&self) -> *const u8 { ... }
fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
where Self: Sized { ... }
}Expand description
An owned, stable byte buffer that can back an IO read or write.
§Safety
The backing storage must stay valid and at a fixed address for as long as a
backend owns the buffer during an in-flight op: from when the backend reads
buf_ptr / buf_mut_ptr until the
op completes (the kernel may read/write it after the call returns). A heap
buffer (Vec/BytesMut/Bytes) satisfies this trivially, moving the handle
moves a header, not the allocation. An inline (stack) buffer (ArrayBuf)
satisfies it too if: a completion backend moves the buffer into its op-slab
before taking the pointer and does not move it again until the CQE, so the
address the kernel sees stays fixed for the op.
Required Methods§
Provided Methods§
fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>where
Self: Sized,
fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>where
Self: Sized,
Restrict this buffer to the sub-range [begin, end), consuming it.
Used by writers to express “the not-yet-written tail” without copying.
Recover the original buffer with Slice::into_inner.
The range must lie within the initialized region [0, buf_len), the
resulting Slice reports its whole length as initialized, so slicing into
the uninitialized spare would expose uninitialized bytes as readable.
Panics if the range is out of bounds for buf_len.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".