Struct Buffer

Source
pub struct Buffer<T> { /* private fields */ }

Implementations§

Source§

impl<T> Buffer<T>

Source

pub const fn from_initializer(initializer: BufferInitializer<T>) -> Self

Create a new buffer from an initializer.

Source

pub const fn uninit(inner: T) -> Self

Create a new buffer, defaulting to not being initialized, nor filled. Prefer new if the buffer is already initialized.

Source

pub fn into_raw_parts(self) -> (BufferInitializer<T>, usize)

Move out the buffer initializer, which contains the inner buffer and initialization cursor, and get the filledness cursor.

Source

pub fn into_initializer(self) -> BufferInitializer<T>

Source

pub fn into_inner(self) -> T

Move out the inner buffer, being uninitialized or initialized based on whatever it was when this buffer was constructed.

Use try_into_init if the buffer is initialized.

Source

pub const fn items_filled(&self) -> usize

Get the number of items that are currently filled, within the buffer. Note that this is different from the number of initialized items; use items_initialized for that.

Source

pub fn by_ref(&mut self) -> BufferRef<'_, T>

Source

pub const fn initializer(&self) -> &BufferInitializer<T>

Source

pub fn initializer_mut(&mut self) -> &mut BufferInitializer<T>

Source§

impl<T, Item> Buffer<AsUninit<T>>
where T: Deref<Target = [Item]> + DerefMut + TrustedDeref,

Source

pub fn new(init: T) -> Self

Source§

impl<T> Buffer<T>
where T: Initialize,

Source

pub fn capacity(&self) -> usize

Source

pub fn remaining(&self) -> usize

Get the number of items that may be filled before the buffer is full.

Source

pub fn is_full(&self) -> bool

Check whether the buffer is completely filled, and thus also initialized.

Source

pub fn is_empty(&self) -> bool

Check whether the buffer is empty. It can be partially or fully initialized however.

Source

pub fn filled_part(&self) -> &[T::Item]

Retrieve a shared slice to the filled part of the buffer.

Source

pub fn filled_part_mut(&mut self) -> &mut [T::Item]

Retrieve a mutable slice to the filled part of the buffer.

Source

pub fn unfilled_part(&self) -> &[MaybeUninit<T::Item>]

Get a shared slice to the unfilled part, which may be uninitialized.

Source

pub unsafe fn unfilled_part_mut(&mut self) -> &mut [MaybeUninit<T::Item>]

Get a mutable reference to the unfilled part of the buffer, which may overlap with the initialized-but-nonfilled region.

§Safety

Due to the possibility of an overlap between the part that is initialized and the part that is unfilled, the caller must ensure that the resulting slice is never used to deinitialize the buffer.

It is thus recommended to use append or fill_by_repeating instead, since those are the by far most common operations to do when initializing. However, code that requires interfacing with other APIs such as system calls, need to use this function.

If mutable access really is needed for the unfilled region in safe code, consider using all_parts_mut.

Source

pub fn filled_unfilled_parts(&self) -> (&[T::Item], &[MaybeUninit<T::Item>])

Borrow both the filled and unfilled parts immutably.

Source

pub fn all_parts(&self) -> BufferParts<'_, T::Item>

Borrow the filled part, the unfilled but initialized part, and the unfilled and uninitialized part.

Source

pub fn all_parts_mut(&mut self) -> BufferPartsMut<'_, T::Item>

Source

pub unsafe fn filled_unfilled_parts_mut( &mut self, ) -> (&mut [T::Item], &mut [MaybeUninit<T::Item>])

Borrow both the filled and the unfilled parts, mutably.

§Safety

This is unsafe as the uninit part may have items in it that are tracked to be initialized. It is hence the responsibility of the caller to ensure that the buffer is not deinitialized by writing MaybeUninit::uninit() to it.

Source

pub fn unfilled_init_part(&self) -> &[T::Item]

Source

pub fn unfilled_init_part_mut(&mut self) -> &mut [T::Item]

Get the initialized part of the unfilled part, if there is any.

Source

pub fn unfilled_uninit_part(&self) -> &[MaybeUninit<T::Item>]

Source

pub fn unfilled_uninit_part_mut(&mut self) -> &mut [MaybeUninit<T::Item>]

Get the uninitialized part of the unfilled part, if there is any.

Source

pub fn unfilled_parts(&mut self) -> (&[T::Item], &[MaybeUninit<T::Item>])

Source

pub fn unfilled_parts_mut( &mut self, ) -> (&mut [T::Item], &mut [MaybeUninit<T::Item>])

Source

pub fn revert_to_start(&mut self)

Revert the internal cursor to 0, forgetting about the initialized items.

Source

pub fn append(&mut self, slice: &[T::Item])
where T::Item: Copy,

Source

pub fn advance(&mut self, count: usize)

Source

pub fn advance_to_init_part(&mut self)

Source

pub unsafe fn assume_init(&mut self, count: usize)

Increment the counter that marks the progress of filling, as well as the initialization progress, count items.

§Safety

This does not initialize nor fill anything, and it is hence up to the user to ensure that no uninitialized items are marked initialized.

Source

pub unsafe fn assume_init_all(&mut self)

Mark the buffer as fully filled and initialized, without actually filling the buffer.

§Safety

For this to be safe, the caller must ensure that every single item in the slice that the buffer wraps, is initialized.

Source

pub fn fill_by_repeating(&mut self, item: T::Item)
where T::Item: Copy,

Source§

impl<T> Buffer<T>
where T: Initialize<Item = u8>,

Source

pub fn fill_by_zeroing(&mut self)

Source§

impl<'a> Buffer<AsUninit<&'a mut [u8]>>

Source

pub fn from_slice_mut(slice: &'a mut [u8]) -> Self

Source§

impl<'a> Buffer<&'a mut [MaybeUninit<u8>]>

Source

pub fn from_uninit_slice_mut(slice: &'a mut [MaybeUninit<u8>]) -> Self

Trait Implementations§

Source§

impl<T> Debug for Buffer<T>
where T: Initialize,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Buffer<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Buffer<T>
where T: RefUnwindSafe,

§

impl<T> Send for Buffer<T>
where T: Send,

§

impl<T> Sync for Buffer<T>
where T: Sync,

§

impl<T> Unpin for Buffer<T>
where T: Unpin,

§

impl<T> UnwindSafe for Buffer<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.