funnel 1.1.0

A simple data structure that makes it easy to read from multiple channels from a single source
Documentation
  • Coverage
  • 72.73%
    8 out of 11 items documented1 out of 8 items with examples
  • Size
  • Source code size: 11.77 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.67 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zsck

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,
    });
}