Skip to main content

IoBufMut

Trait IoBufMut 

Source
pub trait IoBufMut: IoBuf + SetLen {
    // Required method
    fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>];

    // Provided methods
    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 reserve(&mut self, len: usize) -> Result<(), ReserveError> { ... }
    fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError> { ... }
    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

A trait for mutable buffers.

The IoBufMut trait is implemented by buffer types that can be passed to mutable completion-based IO operations, like reading content from a file and write to the buffer. This trait will take all space of a buffer into account, including uninitialized bytes.

Required Methods§

Source

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Get the full mutable slice of the buffer, including both initialized and uninitialized bytes.

Provided Methods§

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 reserve(&mut self, len: usize) -> Result<(), ReserveError>

Reserve additional capacity for the buffer.

By default, this checks if the spare capacity is enough to fit in len-bytes. If it does, returns Ok(()), and otherwise returns Err(ReserveError::NotSupported). Types that support dynamic resizing (like Vec<u8>) will override this method to actually reserve capacity. The return value indicates whether the reservation succeeded. See ReserveError for details.

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 reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>

Reserve exactly len additional capacity for the buffer.

By default this falls back to IoBufMut::reserve. Types that support dynamic resizing (like Vec<u8>) will override this method to actually reserve capacity. The return value indicates whether the exact reservation succeeded. See ReserveExactError for details.

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

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", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl IoBufMut for BorrowedBuf<'static>

Available on crate feature read_buf only.
Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

impl IoBufMut for BytesMut

Available on crate feature bytes only.
Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

fn reserve(&mut self, len: usize) -> Result<(), ReserveError>

Source§

fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>

Source§

impl IoBufMut for [u8]

Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

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

Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

fn reserve(&mut self, len: usize) -> Result<(), ReserveError>

Source§

fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>

Source§

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

Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

fn reserve(&mut self, len: usize) -> Result<(), ReserveError>

Source§

fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>

Source§

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

Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

fn reserve(&mut self, len: usize) -> Result<(), ReserveError>

Source§

fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>

Source§

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

Available on crate feature arrayvec only.
Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

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

Available on crate feature smallvec only.
Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Source§

fn reserve(&mut self, len: usize) -> Result<(), ReserveError>

Source§

fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>

Source§

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

Source§

fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]

Implementors§