Macro branch_inputs

Source
macro_rules! branch_inputs {
    ($(( $($x:expr),+ $(,)? )),* $(,)?) => { ... };
    ($($x:expr),+ $(,)?) => { ... };
}
Expand description

Defines an idiomatic way to provide values to a static branching producer stage (i.e. concrete input values).

A list of tuples of values (of possibly different types) can be provided, and those values will be boxed and then put into a Vec.

§Examples

Here’s an example of what is returned by the macro call.

use async_pipes::{BoxedAnySend, branch_inputs};

let inputs: Vec<Vec<BoxedAnySend>> = branch_inputs![
    (1usize, 1i32, 1u8),
    (2usize, 2i32, 2u8),
    (3usize, 3i32, 3u8),
];

assert_eq!(inputs.len(), 3);

Here’s an example of the macro being used in a pipeline.

use async_pipes::{branch_inputs, Pipeline};
use async_pipes::WorkerOptions;

#[tokio::main]
async fn main() {
    Pipeline::builder()
        .with_branching_inputs(
            vec!["One", "Two"],
            branch_inputs![
                (1usize, "Hello"),
                (1usize, "World"),
                (1usize, "!"),
            ],
        )
        .with_consumer("One", WorkerOptions::default(), |value: usize| async move {
            /* ... */
        })
        .with_consumer("Two", WorkerOptions::default(), |value: &'static str| async move {
            /* ... */
        })
        .build()
        .unwrap()
        .wait()
        .await;
}