Struct TryIter

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

An iterator that attempts to yield all pending values for a Receiver, created by try_iter.

None will be returned when there are no pending values remaining or if the corresponding channel has hung up.

This iterator will never block the caller in order to wait for data to become available. Instead, it will return None.

Examples

use std::sync::mpsc::channel;
use std::thread;
use std::time::Duration;

let (sender, receiver) = channel();

// Nothing is in the buffer yet
assert!(receiver.try_iter().next().is_none());
println!("Nothing in the buffer...");

thread::spawn(move || {
    sender.send(1).unwrap();
    sender.send(2).unwrap();
    sender.send(3).unwrap();
});

println!("Going to sleep...");
thread::sleep(Duration::from_secs(2)); // block for two seconds

for x in receiver.try_iter() {
    println!("Got: {x}");
}

Implementations

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

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

fn next(self: &mut Self) -> Option<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> UnwindSafe for TryIter<'a, T>

impl<'a, T: $crate::fmt::Debug + 'a> Debug for TryIter<'a, T>

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

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> From for TryIter<'a, T>

fn from(t: T) -> T

Returns the argument unchanged.

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>