[][src]Struct crossbeam_channel::TryIter

pub struct TryIter<'a, T: 'a> { /* fields omitted */ }

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

Trait Implementations

impl<'a, T> Iterator for TryIter<'a, T>[src]

type Item = T

The type of the elements being iterated over.

impl<'a, T> Debug for TryIter<'a, T>[src]

Auto Trait Implementations

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

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

impl<'a, T> Sync for TryIter<'a, T> where
    T: Send

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

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

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]