Trait IoBufMut
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 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 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§
fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
Get the full mutable slice of the buffer, including both initialized and uninitialized bytes.
Provided Methods§
fn buf_capacity(&mut self) -> usize
fn buf_capacity(&mut self) -> usize
Total capacity of the buffer, including both initialized and uninitialized bytes.
fn buf_mut_ptr(&mut self) -> *mut MaybeUninit<u8>
fn buf_mut_ptr(&mut self) -> *mut MaybeUninit<u8>
Get the raw mutable pointer to the buffer.
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
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.
fn reserve(&mut self, len: usize) -> Result<(), ReserveError>
fn reserve(&mut self, len: usize) -> Result<(), ReserveError>
Reserve additional capacity for the buffer.
This is a no-op by default. 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.
fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>
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, which is a no-op
for most types. 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.
fn uninit(self) -> Uninit<Self>where
Self: Sized,
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);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§
§impl IoBufMut for BorrowedBuf<'static>
Available on crate feature read_buf only.
impl IoBufMut for BorrowedBuf<'static>
read_buf only.fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
§impl<B> IoBufMut for &'static mut B
impl<B> IoBufMut for &'static mut B
fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
fn reserve(&mut self, len: usize) -> Result<(), ReserveError>
fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>
§impl<const N: usize> IoBufMut for SmallVec<[u8; N]>
Available on crate feature smallvec only.
impl<const N: usize> IoBufMut for SmallVec<[u8; N]>
smallvec only.fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
fn reserve(&mut self, len: usize) -> Result<(), ReserveError>
fn reserve_exact(&mut self, len: usize) -> Result<(), ReserveExactError>
Implementors§
impl IoBufMut for BytesMut
bytes only.impl<A> IoBufMut for Vec<u8, A>where
A: Allocator + 'static,
impl<B, A> IoBufMut for Box<B, A>
impl<T> IoBufMut for Slice<T>where
T: IoBufMut,
impl<T> IoBufMut for Uninit<T>where
T: IoBufMut,
impl<T> IoBufMut for VectoredBufIter<T>where
T: IoVectoredBufMut,
impl<const N: usize> IoBufMut for ArrayVec<u8, N>
arrayvec only.