pub unsafe trait IoBuf: Unpin + 'static {
// Required methods
fn read_ptr(&self) -> *const u8;
fn bytes_init(&self) -> usize;
// Provided methods
fn as_slice(&self) -> &[u8] ⓘ { ... }
fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
where Self: Sized { ... }
unsafe fn slice_unchecked(
self,
range: impl RangeBounds<usize>,
) -> Slice<Self>
where Self: Sized { ... }
}
Expand description
An io_uring
compatible buffer.
The IoBuf
trait is implemented by buffer types that can be passed to
io_uring operations. Users will not need to use this trait directly, except
for the slice
method.
§Slicing
Because buffers are passed by ownership to the runtime, Rust’s slice API
(&buf[..]
) cannot be used. Instead, monoio
provides an owned slice
API: slice()
. The method takes ownership of the buffer and returns a
Slice<Self>
type that tracks the requested offset.
§Safety
impl it safely
Required Methods§
Sourcefn read_ptr(&self) -> *const u8
fn read_ptr(&self) -> *const u8
Returns a raw pointer to the vector’s buffer.
This method is to be used by the monoio
runtime and it is not
expected for users to call it directly.
monoio
Runtime will Box::pin
the buffer. Runtime makes sure
the buffer will not be moved, and the implement must ensure
as_ptr
returns the same valid address.
Kernel will read bytes_init
-length data from the pointer.
Sourcefn bytes_init(&self) -> usize
fn bytes_init(&self) -> usize
Number of initialized bytes.
This method is to be used by the monoio
runtime and it is not
expected for users to call it directly.
For Vec
, this is identical to len()
.
Provided Methods§
Sourcefn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>where
Self: Sized,
fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>where
Self: Sized,
Returns a view of the buffer with the specified range.
Sourceunsafe fn slice_unchecked(self, range: impl RangeBounds<usize>) -> Slice<Self>where
Self: Sized,
unsafe fn slice_unchecked(self, range: impl RangeBounds<usize>) -> Slice<Self>where
Self: Sized,
Returns a view of the buffer with the specified range without boundary checking.
§Safety
Range must be within the bounds of the buffer.