Struct BorrowedCursor
struct BorrowedCursor<'a> { ... }
A writeable view of the unfilled portion of a BorrowedBuf.
The unfilled portion consists of an initialized and an uninitialized part; see BorrowedBuf
for details.
Data can be written directly to the cursor by using append or
indirectly by getting a slice of part or all of the cursor and writing into the slice. In the
indirect case, the caller must call advance after writing to inform
the cursor how many bytes have been written.
Once data is written to the cursor, it becomes part of the filled portion of the underlying
BorrowedBuf and can no longer be accessed or re-written by the cursor. I.e., the cursor tracks
the unfilled part of the underlying BorrowedBuf.
The lifetime 'a is a bound on the lifetime of the underlying buffer (which means it is a bound
on the data in that buffer by transitivity).
Implementations
impl<'a> BorrowedCursor<'a>
fn reborrow<'this>(self: &'this mut Self) -> BorrowedCursor<'this>Reborrows this cursor by cloning it with a smaller lifetime.
Since a cursor maintains unique access to its underlying buffer, the borrowed cursor is not accessible while the new cursor exists.
fn capacity(self: &Self) -> usizeReturns the available space in the cursor.
fn written(self: &Self) -> usizeReturns the number of bytes written to the
BorrowedBufthis cursor was created from.In particular, the count returned is shared by all reborrows of the cursor.
fn init_mut(self: &mut Self) -> &mut [u8]Returns a mutable reference to the initialized portion of the cursor.
unsafe fn as_mut(self: &mut Self) -> &mut [MaybeUninit<u8>]Returns a mutable reference to the whole cursor.
Safety
The caller must not uninitialize any bytes in the initialized portion of the cursor.
fn advance(self: &mut Self, n: usize) -> &mut SelfAdvances the cursor by asserting that
nbytes have been filled.After advancing, the
nbytes are no longer accessible via the cursor and can only be accessed via the underlying buffer. I.e., the buffer's filled portion grows bynelements and its unfilled portion (and the capacity of this cursor) shrinks bynelements.If less than
nbytes initialized (by the cursor's point of view),set_initshould be called first.Panics
Panics if there are less than
nbytes initialized.unsafe fn advance_unchecked(self: &mut Self, n: usize) -> &mut SelfAdvances the cursor by asserting that
nbytes have been filled.After advancing, the
nbytes are no longer accessible via the cursor and can only be accessed via the underlying buffer. I.e., the buffer's filled portion grows bynelements and its unfilled portion (and the capacity of this cursor) shrinks bynelements.Safety
The caller must ensure that the first
nbytes of the cursor have been properly initialised.fn ensure_init(self: &mut Self) -> &mut SelfInitializes all bytes in the cursor.
unsafe fn set_init(self: &mut Self, n: usize) -> &mut SelfAsserts that the first
nunfilled bytes of the cursor are initialized.BorrowedBufassumes that bytes are never de-initialized, so this method does nothing when called with fewer bytes than are already known to be initialized.Safety
The caller must ensure that the first
nbytes of the buffer have already been initialized.fn append(self: &mut Self, buf: &[u8])Appends data to the cursor, advancing position within its buffer.
Panics
Panics if
self.capacity()is less thanbuf.len().fn with_unfilled_buf<T, impl FnOnce(&mut BorrowedBuf<'_>) -> T: FnOnce(&mut BorrowedBuf<'_>) -> T>(self: &mut Self, f: impl FnOnce(&mut BorrowedBuf<'_>) -> T) -> TRuns the given closure with a
BorrowedBufcontaining the unfilled part of the cursor.This enables inspecting what was written to the cursor.
Panics
Panics if the
BorrowedBufgiven to the closure is replaced by another one.
impl<'a> Debug for BorrowedCursor<'a>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<'a> Freeze for BorrowedCursor<'a>
impl<'a> RefUnwindSafe for BorrowedCursor<'a>
impl<'a> Send for BorrowedCursor<'a>
impl<'a> Sync for BorrowedCursor<'a>
impl<'a> Unpin for BorrowedCursor<'a>
impl<'a> UnsafeUnpin for BorrowedCursor<'a>
impl<'a> UnwindSafe for BorrowedCursor<'a>
impl<T> Any for BorrowedCursor<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for BorrowedCursor<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for BorrowedCursor<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for BorrowedCursor<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for BorrowedCursor<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for BorrowedCursor<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for BorrowedCursor<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>