Trait IoBuf

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

Source

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.

Source

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§

Source

fn as_slice(&self) -> &[u8]

Returns a slice of the buffer.

Source

fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
where Self: Sized,

Returns a view of the buffer with the specified range.

Source

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.

Implementations on Foreign Types§

Source§

impl IoBuf for &'static str

Source§

impl IoBuf for &'static [u8]

Source§

impl IoBuf for Bytes

Source§

impl IoBuf for BytesMut

Source§

impl IoBuf for Box<[u8]>

Source§

impl IoBuf for Vec<u8>

Source§

impl<T> IoBuf for Rc<T>
where T: IoBuf,

Source§

impl<T> IoBuf for Arc<T>
where T: IoBuf,

Source§

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

Source§

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

Source§

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

Source§

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

Implementors§