funnel

Crates.iofunnel
lib.rsfunnel
version1.1.0
sourcesrc
created_at2016-06-09 01:21:46.955189
updated_at2016-06-09 14:03:11.668242
descriptionA simple data structure that makes it easy to read from multiple channels from a single source
homepagehttps://github.com/zsck/funnel-rs
repositoryhttps://github.com/zsck/funnel-rs
max_upload_size
id5327
size11,621
Zack Mullaly (zsck)

documentation

https://zsck.github.io/projects/funnel/doc/funnel/index.html

README

Funnel

Funnel is a container data structure for receivers for Rust channels. It accumulates receivers whose corresponding senders have been sent to other scopes/functions/threads and provides a simple interface for reading from each of them, eliminating the need to manually iterate through your own collection, read, and handle errors.

You can read the documentation for the project to learn the entire (small) interface the crate presents through the Funnel struct.

Example

extern crate funnel;

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

fn main () {
    // Create a funnel and use it to produce some senders. It will automatically
    // start handling the receivers corresponding to each writer if we use
    // `add_receiver()`.
    let mut fun = Funnel::new();
    let writer1 = fun.add_receiver();
    let writer2 = fun.add_receiver();
   
    // Spin up a thread to write to each sender.
    thread::spawn(move || {
        let _ = writer1.send(32).unwrap();
    });
    thread::spawn(move || {
        let _ = writer2.send(64).unwrap();
    });

    // We can now use the single funnel to read from both receivers, in the order
    // that they were added to the funnel.
    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,
    });
}
Commit count: 0

cargo fmt