IoBuf

Trait IoBuf 

pub trait IoBuf: 'static {
    // Required method
    fn as_init(&self) -> &[u8] ;

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

A trait for immutable buffers.

The IoBuf trait is implemented by buffer types that can be passed to immutable completion-based IO operations, like writing its content to a file. This trait will only take initialized bytes of a buffer into account.

Required Methods§

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

Get the slice of initialized bytes.

Provided Methods§

fn buf_len(&self) -> usize

Length of initialized bytes in the buffer.

fn buf_ptr(&self) -> *const u8

Raw pointer to the buffer.

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_init(), b"world");
§Panics

Panics if:

  • begin > buf_len()
  • end < begin

Implementations on Foreign Types§

§

impl IoBuf for str

§

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

§

impl IoBuf for BorrowedBuf<'static>

Available on crate feature read_buf only.
§

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

§

impl IoBuf for [u8]

§

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

§

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

§

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

§

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

§

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

§

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

Available on crate feature smallvec only.
§

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

§

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

§

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

Implementors§

§

impl IoBuf for Bytes

Available on crate feature bytes only.
§

impl IoBuf for String

§

impl IoBuf for BytesMut

Available on crate feature bytes only.
§

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

§

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

§

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

§

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

§

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

§

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

§

impl<T> IoBuf for VectoredBufIter<T>
where T: IoVectoredBuf,

§

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

Available on crate feature arrayvec only.