Function dptree::filter_map
source · [−]pub fn filter_map<'a, Projection, Input, Output, NewType, Args, Descr>(
proj: Projection
) -> Handler<'a, Input, Output, Descr> where
Input: Clone,
Asyncify<Projection>: Injectable<Input, Option<NewType>, Args> + Send + Sync + 'a,
Input: Insert<NewType> + Send + 'a,
Output: 'a,
Descr: HandlerDescription,
NewType: Send,
Expand description
Constructs a handler that optionally passes a value of a new type further.
If the proj
function returns Some(v)
then v
will be added to the
container and passed further in a handler chain. If the function returns
None
, then the handler will return ControlFlow::Continue
with the old
container.
Examples found in repository?
More examples
examples/descr_locations.rs (line 102)
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() {
#[rustfmt::skip]
let some_tree: Handler<DependencyMap, _, _> = dptree::entry()
.branch(
dptree::filter(|| true)
.endpoint(|| async {})
)
.branch(
dptree::filter_async(|| async { true })
.chain(dptree::filter_map(|| Some(1) ))
.endpoint(|| async {})
);
get_locations(&some_tree).iter().for_each(|(name, loc)| println!("{name: <12} @ {loc}"));
}