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§
Sourcefn 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§
Sourcefn buf_capacity(&mut self) -> usize
fn buf_capacity(&mut self) -> usize
Total capacity of the buffer, including both initialized and uninitialized bytes.
Sourcefn 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.
Sourcefn 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.
Sourcefn extend_from_slice(&mut self, src: &[u8]) -> Result<(), ReserveError>
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.
Sourcefn copy_within<R>(&mut self, src: R, dest: usize)where
R: RangeBounds<usize>,
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.
Sourcefn reserve(&mut self, len: usize) -> Result<(), ReserveError>
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.
Sourcefn 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. 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.
Sourcefn 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);Sourcefn into_writer(self) -> Writer<Self> ⓘwhere
Self: Sized,
fn into_writer(self) -> Writer<Self> ⓘwhere
Self: Sized,
Create a Writer from this buffer, which implements
std::io::Write.
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.
impl IoBufMut for BorrowedBuf<'static>
read_buf only.fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
Source§impl IoBufMut for BytesMut
Available on crate feature bytes only.
impl IoBufMut for BytesMut
bytes 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>
Source§impl<A: Allocator + 'static> IoBufMut for Vec<u8, A>
impl<A: Allocator + 'static> IoBufMut for Vec<u8, A>
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>
Source§impl<B: IoBufMut + ?Sized> IoBufMut for &'static mut B
impl<B: IoBufMut + ?Sized> 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>
Source§impl<B: IoBufMut + ?Sized, A: Allocator + 'static> IoBufMut for Box<B, A>
impl<B: IoBufMut + ?Sized, A: Allocator + 'static> IoBufMut for Box<B, A>
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>
Source§impl<const N: usize> IoBufMut for ArrayVec<u8, N>
Available on crate feature arrayvec only.
impl<const N: usize> IoBufMut for ArrayVec<u8, N>
arrayvec only.fn as_uninit(&mut self) -> &mut [MaybeUninit<u8>]
Source§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.