Trait IoBufMutExt
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§
fn ensure_init(&mut self) -> &mut [u8] ⓘ
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.
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 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.
fn 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.
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, 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);fn 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.
fn as_writer(&mut self) -> WriterRef<'_, Self> ⓘ
fn as_writer(&mut self) -> WriterRef<'_, Self> ⓘ
Create a Writer from a mutable reference of the 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".