Trait IoBufMut

Source
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§

Source

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.

Source

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().

Source

unsafe fn set_init(&mut self, pos: usize)

Updates the number of initialized bytes.

The specified pos becomes the new value returned by IoBuf::bytes_init.

§Safety

The caller must ensure that all bytes starting at stable_mut_ptr() up to pos are initialized and owned by the buffer.

Provided Methods§

Source

fn slice_mut(self, range: impl RangeBounds<usize>) -> SliceMut<Self>
where Self: Sized + IoBuf,

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);
Source

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.

Implementations on Foreign Types§

Source§

impl IoBufMut for BytesMut

Source§

fn write_ptr(&mut self) -> *mut u8

Source§

fn bytes_total(&mut self) -> usize

Source§

unsafe fn set_init(&mut self, init_len: usize)

Source§

impl IoBufMut for Box<[u8]>

Source§

fn write_ptr(&mut self) -> *mut u8

Source§

fn bytes_total(&mut self) -> usize

Source§

unsafe fn set_init(&mut self, _: usize)

Source§

impl IoBufMut for Vec<u8>

Source§

fn write_ptr(&mut self) -> *mut u8

Source§

fn bytes_total(&mut self) -> usize

Source§

unsafe fn set_init(&mut self, init_len: usize)

Source§

impl<T> IoBufMut for ManuallyDrop<T>
where T: IoBufMut,

Source§

fn write_ptr(&mut self) -> *mut u8

Source§

fn bytes_total(&mut self) -> usize

Source§

unsafe fn set_init(&mut self, pos: usize)

Source§

impl<const N: usize> IoBufMut for &'static mut [u8; N]

Source§

fn write_ptr(&mut self) -> *mut u8

Source§

fn bytes_total(&mut self) -> usize

Source§

unsafe fn set_init(&mut self, _: usize)

Source§

impl<const N: usize> IoBufMut for Box<[u8; N]>

Source§

fn write_ptr(&mut self) -> *mut u8

Source§

fn bytes_total(&mut self) -> usize

Source§

unsafe fn set_init(&mut self, _: usize)

Implementors§