Trait compio_buf::IoBuf

source ·
pub unsafe trait IoBuf: Unpin + 'static {
    // Required methods
    fn as_buf_ptr(&self) -> *const u8;
    fn buf_len(&self) -> usize;
    fn buf_capacity(&self) -> usize;

    // Provided methods
    fn as_slice(&self) -> &[u8]  { ... }
    fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
       where Self: Sized { ... }
}
Expand description

A trait for buffers.

The IoBuf trait is implemented by buffer types that can be passed to compio operations. Users will not need to use this trait directly.

Safety

Buffers passed to compio operations must refer to a stable memory region. While the runtime holds ownership to a buffer, the pointer returned by as_buf_ptr must remain valid even if the IoBuf value is moved, i.e., the type implementing IoBuf should point to somewhere else.

Required Methods§

source

fn as_buf_ptr(&self) -> *const u8

Returns a raw pointer to the vector’s buffer.

This method is to be used by the compio runtime and it is not expected for users to call it directly.

The implementation must ensure that, while the compio runtime owns the value, the pointer returned does not change.

source

fn buf_len(&self) -> usize

Number of initialized bytes.

This method is to be used by the compio runtime and it is not expected for users to call it directly.

For Vec, this is identical to len().

source

fn buf_capacity(&self) -> usize

Total size of the buffer, including uninitialized memory, if any.

This method is to be used by the compio runtime and it is not expected for users to call it directly.

For Vec, this is identical to capacity().

Provided Methods§

source

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

Get the initialized part 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.

This method is similar to Rust’s slicing (&buf[..]), but takes ownership of the buffer.

Examples
use compio_buf::IoBuf;

let buf = b"hello world";
assert_eq!(buf.slice(6..).as_slice(), b"world");

Implementations on Foreign Types§

source§

impl IoBuf for &'static str

source§

impl IoBuf for &'static [u8]

source§

impl IoBuf for &'static mut str

source§

impl IoBuf for &'static mut [u8]

source§

impl IoBuf for String

source§

impl IoBuf for BorrowedBuf<'static>

source§

impl IoBuf for Bytes

source§

impl IoBuf for BytesMut

source§

impl<A: Allocator + Unpin + 'static> IoBuf for Vec<u8, A>

source§

impl<const N: usize> IoBuf for ArrayVec<u8, N>

Implementors§

source§

impl<T: IoBuf> IoBuf for Slice<T>