Skip to main content

IoBufExt

Trait IoBufExt 

Source
pub trait IoBufExt: IoBuf {
    // 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

Extension trait for immutable buffers.

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, IoBufExt};

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".

Implementors§

Source§

impl<B> IoBufExt for B
where B: IoBuf + ?Sized,