Skip to main content

IoBuf

Trait IoBuf 

Source
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 is_empty(&self) -> bool { ... }
    fn slice(self, range: impl RangeBounds<usize>) -> Slice<Self>
       where Self: Sized { ... }
    fn into_reader(self) -> Reader<Self> 
       where Self: Sized { ... }
    fn as_reader(&self) -> ReaderRef<'_, Self>  { ... }
}
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§

Source

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

Get the slice of initialized bytes.

Provided Methods§

Source

fn buf_len(&self) -> usize

Length of initialized bytes in the buffer.

Source

fn buf_ptr(&self) -> *const u8

Raw pointer to the buffer.

Source

fn is_empty(&self) -> bool

Check if the buffer is empty.

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

Panics if:

  • begin > buf_len()
  • end < begin
Source

fn into_reader(self) -> Reader<Self>
where Self: Sized,

Create a Reader from this buffer, which implements std::io::Read.

Source

fn as_reader(&self) -> ReaderRef<'_, Self>

Create a ReaderRef from a reference of the buffer, which implements std::io::Read.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl IoBuf for str

Source§

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

Source§

impl IoBuf for String

Source§

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

Source§

impl IoBuf for BorrowedBuf<'static>

Available on crate feature read_buf only.
Source§

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

Source§

impl IoBuf for Bytes

Available on crate feature bytes only.
Source§

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

Source§

impl IoBuf for BytesMut

Available on crate feature bytes only.
Source§

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

Source§

impl IoBuf for [u8]

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Available on crate feature arrayvec only.
Source§

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

Source§

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

Available on crate feature smallvec only.
Source§

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

Source§

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

Source§

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

Implementors§