Skip to main content

IoBufMutExt

Trait IoBufMutExt 

Source
pub trait IoBufMutExt: IoBufMut {
    // Provided methods
    fn ensure_init(&mut self) -> &mut [u8]  { ... }
    fn buf_capacity(&mut self) -> usize { ... }
    fn buf_mut_ptr(&mut self) -> *mut MaybeUninit<u8> { ... }
    fn as_mut_slice(&mut self) -> &mut [u8]  { ... }
    fn extend_from_slice(&mut self, src: &[u8]) -> Result<(), ReserveError> { ... }
    fn copy_within<R>(&mut self, src: R, dest: usize)
       where R: RangeBounds<usize> { ... }
    fn uninit(self) -> Uninit<Self>
       where Self: Sized { ... }
    fn into_writer(self) -> Writer<Self> 
       where Self: Sized { ... }
    fn as_writer(&mut self) -> WriterRef<'_, Self>  { ... }
    fn is_filled(&mut self) -> bool { ... }
}
Expand description

Extension trait for mutable buffers.

Provided Methods§

Source

fn ensure_init(&mut self) -> &mut [u8]

Initialize all bytes in the buffer and return them.

Bytes in the already-initialized prefix (0..buf_len()) are preserved. Only the uninitialized tail (buf_len()..buf_capacity()) is zero-initialized.

Source

fn buf_capacity(&mut self) -> usize

Total capacity of the buffer, including both initialized and uninitialized bytes.

Source

fn buf_mut_ptr(&mut self) -> *mut MaybeUninit<u8>

Get the raw mutable pointer to the buffer.

Source

fn as_mut_slice(&mut self) -> &mut [u8]

Get the mutable slice of initialized bytes. The content is the same as IoBuf::as_init, but mutable.

Source

fn extend_from_slice(&mut self, src: &[u8]) -> Result<(), ReserveError>

Extend the buffer by copying bytes from src.

The buffer will reserve additional capacity if necessary, and return an error when reservation failed.

Notice that this may move the memory of the buffer, so it’s UB to call this after the buffer is being pinned.

Source

fn copy_within<R>(&mut self, src: R, dest: usize)
where R: RangeBounds<usize>,

Like slice::copy_within, copy a range of bytes within the buffer to another location in the same buffer. This will count in both initialized and uninitialized bytes.

§Panics

This method will panic if the source or destination range is out of bounds.

Source

fn uninit(self) -> Uninit<Self>
where Self: Sized,

Returns an Uninit, which is a Slice that only exposes uninitialized bytes.

It will always point to the uninitialized area of a IoBufMut even after reading in some bytes, which is done by SetLen. This is useful for writing data into buffer without overwriting any existing bytes.

§Examples
use compio_buf::{IoBuf, IoBufMut, IoBufMutExt};

let mut buf = Vec::from(b"hello world");
buf.reserve_exact(10);
let mut slice = buf.uninit();

assert_eq!(slice.as_init(), b"");
assert_eq!(slice.buf_capacity(), 10);
Source

fn into_writer(self) -> Writer<Self>
where Self: Sized,

Create a Writer from this buffer, which implements std::io::Write.

Source

fn as_writer(&mut self) -> WriterRef<'_, Self>

Create a Writer from a mutable reference of the buffer, which implements std::io::Write.

Source

fn is_filled(&mut self) -> bool

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<B> IoBufMutExt for B
where B: IoBufMut + ?Sized,