Struct rtrb::chunks::WriteChunkUninit[][src]

pub struct WriteChunkUninit<'a, T> { /* fields omitted */ }
Expand description

Structure for writing into multiple (uninitialized) slots in one go.

This is returned from Producer::write_chunk_uninit().

Implementations

Returns two slices for writing to the requested slots.

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.

The extension trait CopyToUninit can be used to safely copy data into those slices.

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).

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

Panics

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

Safety

The user must make sure that the first n elements have been initialized.

Makes the whole chunk available for reading.

Safety

The user must make sure that all elements have been initialized.

Moves items from an iterator into the (uninitialized) slots of the chunk.

The number of moved items is returned.

All moved items are automatically made availabe to be read by the Consumer.

Examples

If the iterator contains too few items, only a part of the chunk is made available for reading:

use rtrb::{RingBuffer, PopError};

let (mut p, mut c) = RingBuffer::new(4);

if let Ok(chunk) = p.write_chunk_uninit(3) {
    assert_eq!(chunk.fill_from_iter([10, 20]), 2);
} else {
    unreachable!();
}
assert_eq!(p.slots(), 2);
assert_eq!(c.pop(), Ok(10));
assert_eq!(c.pop(), Ok(20));
assert_eq!(c.pop(), Err(PopError::Empty));

If the chunk size is too small, some items may remain in the iterator. To be able to keep using the iterator after the call, &mut (or Iterator::by_ref()) can be used.

use rtrb::{RingBuffer, PopError};

let (mut p, mut c) = RingBuffer::new(4);

let mut it = vec![10, 20, 30].into_iter();
if let Ok(chunk) = p.write_chunk_uninit(2) {
    assert_eq!(chunk.fill_from_iter(&mut it), 2);
} else {
    unreachable!();
}
assert_eq!(c.pop(), Ok(10));
assert_eq!(c.pop(), Ok(20));
assert_eq!(c.pop(), Err(PopError::Empty));
assert_eq!(it.next(), Some(30));

Returns the number of slots in the chunk.

Returns true if the chunk contains no slots.

Trait Implementations

Formats the value using the given formatter. Read more

Fills all slots with the Default value.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.