pub fn extract_and_match<S, E, Z, F>(
    f: F
) -> impl Handler<S, E, Output = <AndMatch<Extract<Z, F>> as Handler<S, E>>::Output>
where AndMatch<Extract<Z, F>>: Handler<S, E>,
Expand description

Constructs an extractor event handler that runs when its parameters can be extracted from an event.

This function behaves much like extract, but its composed function must return a Handled and the constructed event handler does not match unless the extraction is successful and the composed function indicates a match.

§Examples

The following constructs an event handler that runs when a management frame can be extracted from a transmission event and only matches when the management frame subtype is supported. (Note that this differs from extracting Buffered<Supported<MgmtFrame>>, as this handler executes for any management frame while that handler would only execute if the frame is supported.)

use Handled::{Matched, Unmatched};

let mut handler = event::on_transmit(event::extract_and_match(|frame: Buffered<MgmtFrame>| {
    let frame = frame.get();
    // ...
    if MgmtFrame::tag(frame).is_supported() { Matched(()) } else { Unmatched }
}));