pub struct Receiver<T> { /* private fields */ }
Expand description
Asynchronous FIFO receiver
Implementations§
Source§impl<T: Unpin> Receiver<T>
impl<T: Unpin> Receiver<T>
Sourcepub fn no_senders(&self) -> bool
pub fn no_senders(&self) -> bool
Returns true if all senders have been dropped
§Example
let (tx, mut rx) = async_fifo::new();
tx.send('z');
// one remaining sender
assert_eq!(rx.no_senders(), false);
// drop it
core::mem::drop(tx);
// all senders are gone
assert_eq!(rx.no_senders(), true);
// No sender, yes, but one item is still in there.
assert_eq!(rx.try_recv(), Some('z'));
assert_eq!(rx.try_recv(), None);
Sourcepub fn recv(&mut self) -> RecvOne<'_, T>
pub fn recv(&mut self) -> RecvOne<'_, T>
Receives one item, asynchronously.
§Example
let (tx, mut rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c']);
// Receive one by one
assert_eq!(rx.recv().await, Ok('a'));
assert_eq!(rx.recv().await, Ok('b'));
assert_eq!(rx.recv().await, Ok('c'));
core::mem::drop(tx);
assert_eq!(rx.recv().await, Err(Closed));
Sourcepub fn recv_many<'a>(&'a mut self, vec: &'a mut Vec<T>) -> FillMany<'a, T>
pub fn recv_many<'a>(&'a mut self, vec: &'a mut Vec<T>) -> FillMany<'a, T>
Receives as many items as possible, into a vector, asynchronously.
The number of received items is returned.
§Example
let (tx, mut rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c', 'd']);
// Pull as much as possible into a vec
let mut bucket = Vec::new();
assert_eq!(rx.recv_many(&mut bucket).await, Ok(4));
assert_eq!(bucket, ['a', 'b', 'c', 'd']);
core::mem::drop(tx);
assert_eq!(rx.recv_many(&mut bucket).await, Err(Closed));
Sourcepub fn recv_exact<'a>(&'a mut self, slice: &'a mut [T]) -> FillExact<'a, T>
pub fn recv_exact<'a>(&'a mut self, slice: &'a mut [T]) -> FillExact<'a, T>
Receives exactly slice.len()
items into a slice, asynchronously.
§Example
let (tx, mut rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c']);
// Pull a specific amount into a slice
let mut buffer = ['_'; 3];
assert_eq!(rx.recv_exact(&mut buffer).await, Ok(3));
assert_eq!(buffer, ['a', 'b', 'c']);
core::mem::drop(tx);
assert_eq!(rx.recv_exact(&mut buffer).await, Err(Closed));
Sourcepub fn recv_array<const N: usize>(&mut self) -> RecvArray<'_, N, T>
pub fn recv_array<const N: usize>(&mut self) -> RecvArray<'_, N, T>
Receives exactly N
items into an array, asynchronously.
§Example
let (tx, mut rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c']);
// Pull a specific amount into an array
assert_eq!(rx.recv_array().await, Ok(['a', 'b', 'c']));
core::mem::drop(tx);
assert_eq!(rx.recv_array::<3>().await, Err(Closed));
Source§impl<T: Unpin> Receiver<T>
impl<T: Unpin> Receiver<T>
Sourcepub fn into_recv<S: RecvStorage<T>>(&mut self) -> Recv<'_, S, T> ⓘ
pub fn into_recv<S: RecvStorage<T>>(&mut self) -> Recv<'_, S, T> ⓘ
Receives some items into custom storage, asynchronously.
Sourcepub fn into_fill<S: FillStorage<T>>(&mut self, storage: S) -> Fill<'_, S, T> ⓘ
pub fn into_fill<S: FillStorage<T>>(&mut self, storage: S) -> Fill<'_, S, T> ⓘ
Receives some items into custom storage, asynchronously.
Source§impl<T: Unpin> Receiver<T>
These methods are only available if you enable the blocking
feature.
impl<T: Unpin> Receiver<T>
These methods are only available if you enable the blocking
feature.
Sourcepub fn recv_blocking(&mut self) -> Result<T, Closed>
pub fn recv_blocking(&mut self) -> Result<T, Closed>
Receives one item, blocking.
Sourcepub fn recv_array_blocking<const N: usize>(&mut self) -> Result<[T; N], Closed>
pub fn recv_array_blocking<const N: usize>(&mut self) -> Result<[T; N], Closed>
Receives exactly N
items into an array, blocking.
Methods from Deref<Target = Consumer<T>>§
Sourcepub fn no_producers(&self) -> bool
pub fn no_producers(&self) -> bool
Returns true if all producers have been dropped
§Example
let (tx, rx) = async_fifo::new();
tx.send('z');
// one remaining producer
assert_eq!(rx.no_producers(), false);
// drop it
core::mem::drop(tx);
// all producers are gone
assert_eq!(rx.no_producers(), true);
// No producer, yes, but one item is still in there.
assert_eq!(rx.try_recv(), Some('z'));
assert_eq!(rx.try_recv(), None);
Sourcepub fn try_recv(&self) -> Option<T>
pub fn try_recv(&self) -> Option<T>
Tries to receive one item.
§Example
let (tx, rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c']);
// Receive one by one
assert_eq!(rx.try_recv(), Some('a'));
assert_eq!(rx.try_recv(), Some('b'));
assert_eq!(rx.try_recv(), Some('c'));
assert_eq!(rx.try_recv(), None);
Sourcepub fn try_recv_many(&self, vec: &mut Vec<T>) -> Option<usize>
pub fn try_recv_many(&self, vec: &mut Vec<T>) -> Option<usize>
Tries to receive as many items as possible, into a vector.
If at least one item is received, the number of received items is returned.
§Example
let (tx, rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c', 'd']);
// Pull as much as possible into a vec
let mut bucket = Vec::new();
assert_eq!(rx.try_recv_many(&mut bucket), Some(4));
assert_eq!(bucket, ['a', 'b', 'c', 'd']);
assert_eq!(rx.try_recv(), None);
Sourcepub fn try_recv_exact(&self, slice: &mut [T]) -> Option<()>
pub fn try_recv_exact(&self, slice: &mut [T]) -> Option<()>
Tries to receive exactly slice.len()
items into a slice.
§Example
let (tx, rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c']);
// Pull a specific amount into a slice
let mut buffer = ['_'; 3];
assert!(rx.try_recv_exact(&mut buffer).is_some());
assert_eq!(buffer, ['a', 'b', 'c']);
assert_eq!(rx.try_recv(), None);
Sourcepub fn try_recv_array<const N: usize>(&self) -> Option<[T; N]>
pub fn try_recv_array<const N: usize>(&self) -> Option<[T; N]>
Tries to receive exactly N
items into an array.
§Example
let (tx, rx) = async_fifo::new();
tx.send_iter(['a', 'b', 'c']);
// Pull a specific amount into an array
assert_eq!(rx.try_recv_array(), Some(['a', 'b', 'c']));
assert_eq!(rx.try_recv(), None);
Sourcepub fn try_recv_into<S: Storage<T>>(&self, storage: S) -> Result<S::Output, S>
pub fn try_recv_into<S: Storage<T>>(&self, storage: S) -> Result<S::Output, S>
Tries to receive some items into custom storage.