pub struct OwnedCursor { /* private fields */ }
Expand description
A write-only cursor over an OwnedBuf
.
Created via OwnedBuf::unfilled
or using Into
.
An OwnedCursor
represents the unfilled portion of an OwnedBuf
, as data is filled it becomes
inaccessible via the cursor, so the start of the cursor (or current position, if you think of it
that way) is always the first unfilled byte of the underlying buffer. An OwnedCursor
can contain
both initialized and uninitialized bytes.
An OwnedCursor
takes ownership of the OwnedBuf
when it is created. It can always be converted
back into and OwnedBuf
.
Implementations§
Source§impl OwnedCursor
impl OwnedCursor
Sourcepub fn init_mut(&mut self) -> &mut [u8] ⓘ
pub fn init_mut(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the initialized portion of the cursor.
Sourcepub fn uninit_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub fn uninit_mut(&mut self) -> &mut [MaybeUninit<u8>]
Returns a mutable reference to the uninitialized part of the cursor.
It is safe to uninitialize any of these bytes.
Sourcepub unsafe fn as_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub unsafe fn as_mut(&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.
Sourcepub unsafe fn advance(&mut self, n: usize) -> &mut Self
pub unsafe fn advance(&mut self, n: usize) -> &mut Self
Advance 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.
Sourcepub fn ensure_init(&mut self) -> &mut Self
pub fn ensure_init(&mut self) -> &mut Self
Initializes all bytes in the cursor.
Sourcepub unsafe fn set_init(&mut self, n: usize) -> &mut Self
pub unsafe fn set_init(&mut self, n: usize) -> &mut Self
Asserts that the first n
unfilled bytes of the cursor are initialized.
OwnedBuf
assumes 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 n
bytes of the cursor have already been initialized.
Sourcepub fn write_slice(&mut self, data: &[u8])
pub fn write_slice(&mut self, data: &[u8])
Copies data
to the start of the cursor and advances the cursor.
§Panics
Panics if self.capacity()
is less than data.len()
.
Trait Implementations§
Source§impl Into<OwnedCursor> for OwnedBuf
impl Into<OwnedCursor> for OwnedBuf
Source§fn into(self) -> OwnedCursor ⓘ
fn into(self) -> OwnedCursor ⓘ
Source§impl Write for OwnedCursor
impl Write for OwnedCursor
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)