Struct WriteChunk

Source
pub struct WriteChunk<'a, T: Send + 'static>(/* private fields */);
Expand description

Structure for writing into multiple (Default-initialized) slots in one go.

This is returned from Producer::write_chunk().

To obtain uninitialized slots, use Producer::write_chunk_uninit() instead, which also allows moving items from an iterator into the ring buffer by means of WriteChunkUninit::fill_from_iter().

Implementations§

Source§

impl<T> WriteChunk<'_, T>
where T: Default + Send + 'static,

Source

pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])

Returns two slices for writing to the requested slots.

All slots are initially filled with their Default value.

The first slice can only be empty if 0 slots have been requested. If the first slice contains all requested slots, the second one is empty.

After writing to the slots, they are not automatically made available to be read by the Consumer. This has to be explicitly done by calling commit() or commit_all(). If items are written but not committed afterwards, they will not become available for reading and they will be leaked (which is only relevant if T implements Drop).

Source

pub fn commit(self, n: usize)

Makes the first n slots of the chunk available for reading.

The rest of the chunk is dropped.

§Panics

Panics if n is greater than the number of slots in the chunk.

Source

pub fn commit_all(self)

Makes the whole chunk available for reading.

Source

pub fn len(&self) -> usize

Returns the number of slots in the chunk.

Source

pub fn is_empty(&self) -> bool

Returns true if the chunk contains no slots.

Trait Implementations§

Source§

impl<'a, T: Debug + Send + 'static> Debug for WriteChunk<'a, T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Send + 'static> Drop for WriteChunk<'_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, T> From<WriteChunkUninit<'a, T>> for WriteChunk<'a, T>
where T: Default + Send + 'static,

Source§

fn from(chunk: WriteChunkUninit<'a, T>) -> Self

Fills all slots with the Default value.

Auto Trait Implementations§

§

impl<'a, T> Freeze for WriteChunk<'a, T>

§

impl<'a, T> !RefUnwindSafe for WriteChunk<'a, T>

§

impl<'a, T> Send for WriteChunk<'a, T>

§

impl<'a, T> !Sync for WriteChunk<'a, T>

§

impl<'a, T> Unpin for WriteChunk<'a, T>
where T: Unpin,

§

impl<'a, T> !UnwindSafe for WriteChunk<'a, T>

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.