Struct BorrowedBuf
pub struct BorrowedBuf<'data, T> { pub(in ::io::borrowed_buf) buf: &'data mut [MaybeUninit<T>], pub(in ::io::borrowed_buf) filled: usize, pub(in ::io::borrowed_buf) init: bool }
A borrowed buffer of initially uninitialized elements, which is incrementally filled.
This type makes it safer to work with MaybeUninit buffers, such as to read into a buffer
without having to initialize it first. It tracks the region of elements that have been filled
and whether the unfilled region was initialized.
In summary, the contents of the buffer can be visualized as:
[ capacity ]
[ filled | unfilled (may be initialized) ]
A BorrowedBuf is created around some existing elements (or capacity for elements) via a unique
reference (&mut). The BorrowedBuf can be configured (e.g., using clear or set_init), but
cannot be directly written. To write into the buffer, use unfilled to create a
BorrowedCursor. The cursor has write-only access to the unfilled portion of the buffer (you
can think of it as a write-only iterator).
The lifetime 'data is a bound on the lifetime of the underlying elements.
The type is most commonly used to manage bytes, but can manage any type of elements.
Fields
buf: &'data mut [MaybeUninit<T>]The buffer's underlying elements.
filled: usizeThe number of elements of
self.bufthat are known to be filled.init: boolWhether the entire unfilled part of
self.bufhas explicitly been initialized.
Implementations
impl<'data, T> BorrowedBuf<'data, T>
fn capacity(&self) -> usizeReturns the total capacity of the buffer.
fn len(&self) -> usizeReturns the length of the filled part of the buffer.
fn is_init(&self) -> boolReturns
trueif the buffer is initialized.
impl<'data, T: Copy> BorrowedBuf<'data, T>
fn filled(&self) -> &[T]Returns a shared reference to the filled portion of the buffer.
fn filled_mut(&mut self) -> &mut [T]Returns a mutable reference to the filled portion of the buffer.
fn into_filled(self) -> &'data [T]Returns a shared reference to the filled portion of the buffer with its original lifetime.
fn into_filled_mut(self) -> &'data mut [T]Returns a mutable reference to the filled portion of the buffer with its original lifetime.
fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this, T>Returns a cursor over the unfilled part of the buffer.
fn clear(&mut self) -> &mut SelfClears the buffer, resetting the filled region to empty.
The contents of the buffer are not modified.
unsafe fn set_init(&mut self) -> &mut SelfAsserts that the unfilled part of the buffer is initialized.
Safety
All the elements of the buffer must be initialized.
Trait Implementations
impl<'data, T: Copy> From<&'data mut [MaybeUninit<T>]> for BorrowedBuf<'data, T>
fn from(buf: &'data mut [MaybeUninit<T>]) -> BorrowedBuf<'data, T>
impl<'data, T: Copy> From<&'data mut [T]> for BorrowedBuf<'data, T>
fn from(slice: &'data mut [T]) -> BorrowedBuf<'data, T>
impl<'data, T: Copy> From<BorrowedCursor<'data, T>> for BorrowedBuf<'data, T>
fn from(buf: BorrowedCursor<'data, T>) -> BorrowedBuf<'data, T>
impl<T> Debug for BorrowedBuf<'_, T>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<'data, T> !UnwindSafe for BorrowedBuf<'data, T>
impl<'data, T> Freeze for BorrowedBuf<'data, T>
where
&'data mut [MaybeUninit<T>]: Freeze,
impl<'data, T> RefUnwindSafe for BorrowedBuf<'data, T>
where
&'data mut [MaybeUninit<T>]: RefUnwindSafe,
impl<'data, T> Send for BorrowedBuf<'data, T>
where
&'data mut [MaybeUninit<T>]: Send,
impl<'data, T> Sync for BorrowedBuf<'data, T>
where
&'data mut [MaybeUninit<T>]: Sync,
impl<'data, T> Unpin for BorrowedBuf<'data, T>
where
&'data mut [MaybeUninit<T>]: Unpin,
impl<'data, T> UnsafeUnpin for BorrowedBuf<'data, T>
where
&'data mut [MaybeUninit<T>]: UnsafeUnpin,
Blanket Implementations
impl<T> Any for BorrowedBuf<'data, T>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for BorrowedBuf<'data, T>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for BorrowedBuf<'data, T>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for BorrowedBuf<'data, T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for BorrowedBuf<'data, T>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for BorrowedBuf<'data, T>
impl<T, U> Into<U> for BorrowedBuf<'data, T>
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 BorrowedBuf<'data, T>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for BorrowedBuf<'data, T>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>