pub type BoxedAnySend = Box<dyn Any + Send + 'static>;
Expand description
A Box that can hold any value that is Send.
Values sent through pipes are trait objects of this type.
This type is publicly exposed as it’s needed when building a pipeline stage with multiple outputs. Since each output could have a different type, it’s more feasible to define the outputs to use dynamic dispatching rather that static dispatching.
§Examples
Here’s an example of a closure representing the task function given to the pipeline builder when creating a “branching” stage. Three outputs are returned, each of a different type.
use async_pipes::branch;
#[tokio::main]
async fn main() {
let task = |value: String| async move {
let length: usize = value.len();
let excited: String = format!("{}!", value);
let odd_length: bool = length % 2 == 1;
Some(branch![length, excited, odd_length])
};
// E.g.:
// ...
// .with_branching_stage("pipe_in", vec!["pipe_len", "pipe_excited", "pipe_odd"], <task>)
// ...
let mut results = task("hello".to_string()).await.unwrap();
let length = results.remove(0).unwrap().downcast::<usize>().unwrap();
let excited = results.remove(0).unwrap().downcast::<String>().unwrap();
let odd_length = results.remove(0).unwrap().downcast::<bool>().unwrap();
assert_eq!(*length, 5usize);
assert_eq!(*excited, "hello!".to_string());
assert_eq!(*odd_length, true);
}
Aliased Type§
struct BoxedAnySend(/* private fields */);