Struct BorrowedCursor

struct BorrowedCursor<'a> { ... }

A writeable view of the unfilled portion of a BorrowedBuf.

The unfilled portion may be uninitialized; 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) -> usize

Returns the available space in the cursor.

fn written(self: &Self) -> usize

Returns the number of bytes written to the BorrowedBuf this cursor was created from.

In particular, the count returned is shared by all reborrows of the cursor.

fn is_init(self: &Self) -> bool

Returns true if the buffer is initialized.

unsafe fn set_init(self: &mut Self)

Set the buffer as fully initialized.

Safety

All the bytes of the cursor must be initialized.

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 of the cursor if it is initialized.

fn advance_checked(self: &mut Self, n: usize) -> &mut Self

Advances the cursor by asserting that n bytes have been filled.

After advancing, the n bytes are no longer accessible via the cursor and can only be accessed via the underlying buffer. I.e., the buffer's filled portion grows by n elements and its unfilled portion (and the capacity of this cursor) shrinks by n elements.

If less than n bytes initialized (by the cursor's point of view), set_init should be called first.

Panics

Panics if there are less than n bytes initialized.

unsafe fn advance(self: &mut Self, n: usize) -> &mut Self

Advances the cursor by asserting that n bytes have been filled.

After advancing, the n bytes are no longer accessible via the cursor and can only be accessed via the underlying buffer. I.e., the buffer's filled portion grows by n elements and its unfilled portion (and the capacity of this cursor) shrinks by n elements.

Safety

The caller must ensure that the first n bytes of the cursor have been properly initialised.

fn ensure_init(self: &mut Self) -> &mut [u8]

Initializes all bytes in the cursor and returns them.

fn append(self: &mut Self, buf: &[u8])

Appends data to the cursor, advancing position within its buffer.

Panics

Panics if self.capacity() is less than buf.len().

fn with_unfilled_buf<T, impl FnOnce(&mut BorrowedBuf<'_>) -> T: FnOnce(&mut BorrowedBuf<'_>) -> T>(self: &mut Self, f: impl FnOnce(&mut BorrowedBuf<'_>) -> T) -> T

Runs the given closure with a BorrowedBuf containing the unfilled part of the cursor.

This enables inspecting what was written to the cursor.

Panics

Panics if the BorrowedBuf given 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) -> T

Returns the argument unchanged.

impl<T, U> Into for BorrowedCursor<'a>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses 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>