Struct funnel::Funnel [] [src]

pub struct Funnel<T> { /* fields omitted */ }

Funnel maintains a collection of Receivers which it collects messages from to output to a single source.

Methods

impl<T> Funnel<T>
[src]

Creates a new Funnel that received messages of type T with no input sources.

Adds a new input source to the Funnel, which it takes ownership over.

Obtains the number of input sources that are being read from.

Removes a specific input source at a given index.

This method is useful in situations where the owner of the Funnel is keeping track of the indexes of Receivers. It is also useful for removing Receivers that can no longer be read from, indicated by any errors returned by a call to recv().

Creates a new channel, whose Receiver will be managed by the funnel.

Attempts to wait for a value on the oldest Receiver not already received from.

Successive calls to recv() result in calls to the recv() method of successive Receivers managed by the funnel. In doing so, channels are read from in an even distribution. As soon as a value is successfully received, it will be returned as the first element of the tuple returned. recv() will accumulate a Vec containing any errors that may have occurred trying to read from Receivers, as well as the index of those Receivers, allowing users to remove() them if desired. Note that the returned error type is FunnelError, which may take on the NoSourcesError variant. In such cases, the index accompanying the error will be 0, however this error is returned to signify that the length of the sources container is 0 and thus remove()ing index 0 would cause an error.

Examples

use self::funnel::Funnel;
use std::thread;

let mut fun = Funnel::new();
let writer1 = fun.add_receiver();
let writer2 = fun.add_receiver();
thread::spawn(move || {
    let _ = writer1.send(32).unwrap();
});
thread::spawn(move || {
    let _ = writer2.send(64).unwrap();
});
assert!(match fun.recv() {
    (Some(read_value), errors) => read_value == 32 && errors.len() == 0,
    _ => false,
});
assert!(match fun.recv() {
    (Some(read_value), errors) => read_value == 64 && errors.len() == 0,
    _ => false,
});

Trait Implementations

impl<T: Debug> Debug for Funnel<T>
[src]

Formats the value using the given formatter.