Struct ReadBufCursor
pub struct ReadBufCursor<'a> { /* private fields */ }
The cursor part of a ReadBuf, representing the unfilled portion.
This is created by calling [ReadBuf::unfilled()].
ReadBufCursor provides safe and unsafe methods for writing data into the
buffer:
-
Safe approach: Use
put_sliceto copy data from a slice. This handles initialization tracking and cursor advancement automatically. -
Unsafe approach: For zero-copy scenarios or when interfacing with low-level APIs, use
as_mutto get a mutable slice ofMaybeUninit<u8>, then calladvanceafter writing. This is more efficient but requires careful attention to safety invariants.
Example using safe methods
use ReadBuf;
let mut backing = ;
let mut read_buf = new;
assert_eq!;
Example using unsafe methods
use ReadBuf;
let mut backing = ;
let mut read_buf = new;
assert_eq!;
Implementations
impl ReadBufCursor<'_>
unsafe fn as_mut(&mut self) -> &mut [MaybeUninit<u8>]Access the unfilled part of the buffer.
Safety
The caller must not uninitialize any bytes that may have been initialized before.
unsafe fn advance(&mut self, n: usize)Advance the
filledcursor bynbytes.Safety
The caller must take care that
nmore bytes have been initialized.fn remaining(&self) -> usizeReturns the number of bytes that can be written from the current position until the end of the buffer is reached.
This value is equal to the length of the slice returned by
as_mut().fn put_slice(&mut self, src: &[u8])Transfer bytes into
selffromsrcand advance the cursor by the number of bytes written.Panics
selfmust have enough remaining capacity to contain all ofsrc.fn initialize_unfilled(&mut self) -> &mut [u8]Returns a mutable reference to the unfilled part of the buffer, ensuring it is fully initialized.
fn initialize_unfilled_to(&mut self, n: usize) -> &mut [u8]Returns a mutable reference to the first
nbytes of the unfilled part of the buffer, ensuring it is fully initialized.Panics
Panics if
self.remaining()is less thann.
Trait Implementations
impl<'a> Debug for ReadBufCursor<'a>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<'a> !UnwindSafe for ReadBufCursor<'a>
impl<'a> Freeze for ReadBufCursor<'a>
impl<'a> RefUnwindSafe for ReadBufCursor<'a>
impl<'a> Send for ReadBufCursor<'a>
impl<'a> Sync for ReadBufCursor<'a>
impl<'a> Unpin for ReadBufCursor<'a>
impl<'a> UnsafeUnpin for ReadBufCursor<'a>
Blanket Implementations
impl<T> Any for ReadBufCursor<'a>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for ReadBufCursor<'a>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for ReadBufCursor<'a>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for ReadBufCursor<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> Instrument for ReadBufCursor<'a>
impl<T> WithSubscriber for ReadBufCursor<'a>
impl<T, U> Into<U> for ReadBufCursor<'a>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for ReadBufCursor<'a>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for ReadBufCursor<'a>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>