pub fn filter<'a, Pred, Input, Output, FnArgs, Descr>(
pred: Pred
) -> Handler<'a, Input, Output, Descr> where
Asyncify<Pred>: Injectable<Input, bool, FnArgs> + Send + Sync + 'a,
Input: Send + 'a,
Output: 'a,
Descr: HandlerDescription,
Expand description
Constructs a handler that filters input with the predicate pred
.
pred
has an access to all values that are stored in the input container.
If it returns true
, a continuation of the handler will be called,
otherwise the handler returns ControlFlow::Continue
.
Examples found in repository?
More examples
examples/descr_locations.rs (line 97)
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}"));
}