Struct Receiver

Source
pub struct Receiver<T> { /* private fields */ }
Expand description

Asynchronous FIFO receiver

Implementations§

Source§

impl<T: Unpin> Receiver<T>

Source

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);
Source

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));
Source

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));
Source

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));
Source

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>

Source

pub fn into_recv<S: RecvStorage<T>>(&mut self) -> Recv<'_, S, T>

Receives some items into custom storage, asynchronously.

Source

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.

Source

pub fn recv_blocking(&mut self) -> Result<T, Closed>

Receives one item, blocking.

Source

pub fn recv_array_blocking<const N: usize>(&mut self) -> Result<[T; N], Closed>

Receives exactly N items into an array, blocking.

Source

pub fn recv_many_blocking(&mut self, vec: &mut Vec<T>) -> Result<usize, Closed>

Receives as many items as possible, into a vector, blocking.

Source

pub fn recv_exact_blocking(&mut self, slice: &mut [T]) -> Result<usize, Closed>

Receives exactly slice.len() items into a slice, blocking.

Methods from Deref<Target = Consumer<T>>§

Source

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);
Source

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);
Source

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);
Source

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);
Source

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);
Source

pub fn try_recv_into<S: Storage<T>>(&self, storage: S) -> Result<S::Output, S>

Tries to receive some items into custom storage.

Trait Implementations§

Source§

impl<'a> AsyncRead for Receiver<u8>

Source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<IoResult<usize>>

Attempt to read from the AsyncRead into buf. Read more
Source§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>], ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Source§

impl<T: Clone> Clone for Receiver<T>

Source§

fn clone(&self) -> Receiver<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Deref for Receiver<T>

Source§

type Target = Consumer<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Consumer<T>

Dereferences the value.

Auto Trait Implementations§

§

impl<T> Freeze for Receiver<T>

§

impl<T> !RefUnwindSafe for Receiver<T>

§

impl<T> Send for Receiver<T>

§

impl<T> Sync for Receiver<T>

§

impl<T> Unpin for Receiver<T>

§

impl<T> !UnwindSafe for Receiver<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.