pub struct Consumer<T> { /* private fields */ }Expand description
Consumer handle. Move it to the consuming thread.
Implementations§
Source§impl<T> Consumer<T>
impl<T> Consumer<T>
Sourcepub fn try_pop(&mut self) -> Option<T>
pub fn try_pop(&mut self) -> Option<T>
Pop a value. Returns None if the buffer is empty. Wait-free.
Examples found in repository?
examples/demo.rs (line 16)
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}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Consumer<T>
impl<T> !RefUnwindSafe for Consumer<T>
impl<T> Sync for Consumer<T>where
T: Send,
impl<T> Unpin for Consumer<T>
impl<T> UnsafeUnpin for Consumer<T>
impl<T> !UnwindSafe for Consumer<T>
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