pub struct Producer<T> { /* private fields */ }
Expand description
Fifo Production Handle
This is the “sending” half of a FIFO channel.
When you call the methods of this object to send N items, a reservation of N consecutive slots is performed on the underlying FIFO. Then, once this reservation is negociated, all items are pushed into the slots sequentially.
Unlike Consumer
s, Producers implement Clone
.
§Example
let (tx, rx) = async_fifo::new();
// Sending items one by one
tx.send('a');
tx.send('b');
tx.send('c');
// Pouring items from a Vec
let mut vec = vec!['a', 'b', 'c'];
tx.send_iter(vec.drain(..));
// Sending an array of items
let array = ['a', 'b', 'c'];
tx.send_iter(array);
// Sending a slice of primitive items
let slice = ['a', 'b', 'c'].as_slice();
let iter = slice.iter().copied();
tx.send_iter(iter);
// Receiving a total of 12 items
let expected = ['a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c', 'a', 'b', 'c'];
assert_eq!(rx.try_recv_array(), Some(expected));
assert_eq!(rx.try_recv(), None);
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Producer<T>
impl<T> !RefUnwindSafe for Producer<T>
impl<T> Send for Producer<T>
impl<T> Sync for Producer<T>
impl<T> Unpin for Producer<T>
impl<T> !UnwindSafe for Producer<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