compio_buf

Trait IoBuf

Source
pub unsafe trait IoBuf: '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]  { ... }
    unsafe fn as_io_slice(&self) -> IoSlice { ... }
    fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
       where Self: Sized { ... }
    fn filled(&self) -> bool { ... }
}
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

The implementer should ensure the pointer, len and capacity are valid, so that the returned slice of IoBuf::as_slice is valid.

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.

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

unsafe fn as_io_slice(&self) -> IoSlice

Create an IoSlice of this buffer.

§Safety

The return slice will not live longer than Self. It is static to provide convenience from writing self-referenced structure.

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

fn filled(&self) -> bool

Indicate whether the buffer has been filled (uninit portion is empty)

Implementations on Foreign Types§

Source§

impl IoBuf for str

Source§

impl IoBuf for String

Source§

impl IoBuf for BorrowedBuf<'static>

Available on crate feature read_buf only.
Source§

impl IoBuf for Bytes

Available on crate feature bytes only.
Source§

impl IoBuf for BytesMut

Available on crate feature bytes only.
Source§

impl IoBuf for [u8]

Source§

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

Source§

impl<B: IoBuf + ?Sized> IoBuf for &'static B

Source§

impl<B: IoBuf + ?Sized> IoBuf for &'static mut B

Source§

impl<B: IoBuf + ?Sized, A: Allocator + 'static> IoBuf for Box<B, A>

Source§

impl<B: IoBuf + ?Sized, A: Allocator + 'static> IoBuf for Rc<B, A>

Source§

impl<B: IoBuf + ?Sized, A: Allocator + 'static> IoBuf for Arc<B, A>

Source§

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

Available on crate feature arrayvec only.
Source§

impl<const N: usize> IoBuf for SmallVec<[u8; N]>
where [u8; N]: Array<Item = u8>,

Available on crate feature smallvec only.
Source§

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

Implementors§

Source§

impl<T> IoBuf for IndexedIter<T>
where T: Indexable + 'static, T::Output: IoBuf,

Source§

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