Struct TryIter

struct TryIter<'a, T> { ... }

A non-blocking iterator over messages in a channel.

Each call to next returns a message if there is one ready to be received. The iterator never blocks waiting for the next message.

Examples

use std::thread;
use std::time::Duration;
use crossbeam_channel::unbounded;

let (s, r) = unbounded::<i32>();

thread::spawn(move || {
    s.send(1).unwrap();
    thread::sleep(Duration::from_secs(1));
    s.send(2).unwrap();
    thread::sleep(Duration::from_secs(2));
    s.send(3).unwrap();
});

thread::sleep(Duration::from_secs(2));

// Collect all messages from the channel without blocking.
// The third message hasn't been sent yet so we'll collect only the first two.
let v: Vec<_> = r.try_iter().collect();

assert_eq!(v, [1, 2]);

Implementations

impl<'a, T> Freeze for TryIter<'a, T>

impl<'a, T> RefUnwindSafe for TryIter<'a, T>

impl<'a, T> Send for TryIter<'a, T>

impl<'a, T> Sync for TryIter<'a, T>

impl<'a, T> Unpin for TryIter<'a, T>

impl<'a, T> UnsafeUnpin for TryIter<'a, T>

impl<'a, T> UnwindSafe for TryIter<'a, T>

impl<I> IntoIterator for TryIter<'a, T>

fn into_iter(self: Self) -> I

impl<T> Any for TryIter<'a, T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for TryIter<'a, T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for TryIter<'a, T>

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

impl<T> Debug for TryIter<'_, T>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<T> From for TryIter<'a, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Iterator for TryIter<'_, T>

fn next(self: &mut Self) -> Option<<Self as >::Item>

impl<T, U> Into for TryIter<'a, T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for TryIter<'a, T>

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

impl<T, U> TryInto for TryIter<'a, T>

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