pub struct SpscRingBuffer;Expand description
Constructor namespace. Use SpscRingBuffer::with_capacity.
Implementations§
Source§impl SpscRingBuffer
impl SpscRingBuffer
Sourcepub fn with_capacity<T>(requested_capacity: usize) -> (Producer<T>, Consumer<T>)
pub fn with_capacity<T>(requested_capacity: usize) -> (Producer<T>, Consumer<T>)
Build a (producer, consumer) pair backed by a buffer of at least
requested_capacity slots, rounded up to the next power of two.
A floor of 2 is enforced.
Examples found in repository?
examples/demo.rs (line 5)
4fn main() {
5 let (mut tx, mut rx) = SpscRingBuffer::with_capacity::<u32>(16);
6
7 let producer = thread::spawn(move || {
8 for i in 0..10u32 {
9 while tx.try_push(i).is_err() {}
10 }
11 });
12
13 let consumer = thread::spawn(move || {
14 let mut seen = Vec::new();
15 while seen.len() < 10 {
16 if let Some(v) = rx.try_pop() {
17 seen.push(v);
18 }
19 }
20 seen
21 });
22
23 producer.join().unwrap();
24 let seen = consumer.join().unwrap();
25 println!("consumed: {seen:?}");
26}Auto Trait Implementations§
impl Freeze for SpscRingBuffer
impl RefUnwindSafe for SpscRingBuffer
impl Send for SpscRingBuffer
impl Sync for SpscRingBuffer
impl Unpin for SpscRingBuffer
impl UnsafeUnpin for SpscRingBuffer
impl UnwindSafe for SpscRingBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more