pub struct SharedRb<T, C: Container<T>> { /* private fields */ }
Expand description

Ring buffer that could be shared between threads.

Implements Sync. And its Producer and Consumer implement Send.

use std::{thread, vec::Vec};
use ringbuf::SharedRb;

let (mut prod, mut cons) = SharedRb::<i32, Vec<_>>::new(256).split();
thread::spawn(move || {
    prod.push(123).unwrap();
})
.join();
thread::spawn(move || {
    assert_eq!(cons.pop().unwrap(), 123);
})
.join();

Implementations

Creates a new instance of a ring buffer.

Panics if capacity is zero.

Constructs ring buffer from container and counters.

Safety

The items in container inside head..tail range must be initialized, items outside this range must be uninitialized. head and tail values must be valid (see RbBase).

Destructures ring buffer into underlying container and head and tail counters.

Safety

Initialized contents of the container must be properly dropped.

Splits ring buffer into producer and consumer.

This method consumes the ring buffer and puts it on heap in Arc. If you don’t want to use heap the see Self::split_ref.

Splits ring buffer into producer and consumer without using the heap.

In this case producer and consumer stores a reference to the ring buffer, so you also need to store the buffer somewhere.

Trait Implementations

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Returns underlying raw ring buffer memory as slice. Read more

Capacity of the ring buffer. Read more

Head position.

Tail position.

Modulus for head and tail values. Read more

The number of items stored in the buffer at the moment.

The number of vacant places in the buffer at the moment.

Checks if the occupied range is empty.

Checks if the vacant range is empty.

Sets the new head position. Read more

Move head position by count items forward. Read more

Returns a pair of slices which contain, in order, the occupied cells in the ring buffer. Read more

Provides a direct mutable access to the ring buffer occupied memory. Read more

Removes items from the head of ring buffer and drops them. Read more

Sets the new tail position. Read more

Move tail position by count items forward. Read more

Returns a pair of slices which contain, in order, the vacant cells in the ring buffer. Read more

Provides a direct access to the ring buffer vacant memory. Returns a pair of slices of uninitialized memory, the second one may be empty. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

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.