pub unsafe trait IoBufMut: Unpin + 'static {
// Required methods
fn write_ptr(&mut self) -> *mut u8;
fn bytes_total(&mut self) -> usize;
unsafe fn set_init(&mut self, pos: usize);
// Provided methods
fn slice_mut(self, range: impl RangeBounds<usize>) -> SliceMut<Self>
where Self: Sized + IoBuf { ... }
unsafe fn slice_mut_unchecked(
self,
range: impl RangeBounds<usize>,
) -> SliceMut<Self>
where Self: Sized { ... }
}
Expand description
A mutable io_uring
compatible buffer.
The IoBufMut
trait is implemented by buffer types that can be passed to
io_uring operations. Users will not need to use this trait directly.
§Safety
See the safety note of the methods.
Required Methods§
Sourcefn write_ptr(&mut self) -> *mut u8
fn write_ptr(&mut self) -> *mut u8
Returns a raw mutable pointer to the vector’s buffer.
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 write bytes_init
-length data to the pointer.
Sourcefn bytes_total(&mut self) -> usize
fn bytes_total(&mut self) -> usize
Total size of the buffer, including uninitialized memory, if any.
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 capacity()
.
Provided Methods§
Sourcefn slice_mut(self, range: impl RangeBounds<usize>) -> SliceMut<Self>
fn slice_mut(self, range: impl RangeBounds<usize>) -> SliceMut<Self>
Returns a view of the buffer with the specified range.
This method is similar to Rust’s slicing (&buf[..]
), but takes
ownership of the buffer.
§Examples
use monoio::buf::{IoBuf, IoBufMut};
let buf = b"hello world".to_vec();
buf.slice(5..10);
Sourceunsafe fn slice_mut_unchecked(
self,
range: impl RangeBounds<usize>,
) -> SliceMut<Self>where
Self: Sized,
unsafe fn slice_mut_unchecked(
self,
range: impl RangeBounds<usize>,
) -> SliceMut<Self>where
Self: Sized,
Returns a view of the buffer with the specified range.
§Safety
Begin must within the initialized bytes, end must be within the capacity.