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

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl IoBufMut for [u8]

Source§

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

Source§

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

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§

Source§

impl IoBufMut for BorrowedBuf<'static, u8>

Available on crate feature read_buf only.
Source§

impl IoBufMut for BufferRef

Source§

impl IoBufMut for BytesMut

Available on crate feature bytes only.
Source§

impl IoBufMut for MmapMut

Available on crate feature memmap2 only.
Source§

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

Source§

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

Source§

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

Source§

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

Source§

impl<T> IoBufMut for VectoredBufIter<T>

Source§

impl<const N: usize> IoBufMut for AncillaryBuf<N>

Source§

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

Available on crate feature arrayvec only.
Source§

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

Available on crate feature smallvec only.