pub trait Handler<S, E> {
type Output;
Show 13 methods
// Required method
fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>;
// Provided methods
fn map<U, F>(self, f: F) -> Map<Self, F>
where Self: Sized,
F: FnMut(Self::Output) -> U { ... }
fn and<H2>(self, handler: H2) -> And<Self, H2>
where Self: Sized,
H2: Handler<S, E> { ... }
fn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
where Self: Sized,
Self::Output: Try,
H2: Handler<S, E>,
H2::Output: Try<Residual = <Self::Output as Try>::Residual> { ... }
fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
where Self: Sized,
H2: Handler<S, E>,
F: FnMut(Self::Output) -> H2 { ... }
fn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
where Self: Sized,
Self::Output: Try,
H2: Handler<S, E>,
H2::Output: Try<Residual = <Self::Output as Try>::Residual>,
F: FnMut(<Self::Output as Try>::Output) -> H2 { ... }
fn or<H2>(self, handler: H2) -> Or<Self, H2>
where Self: Sized,
H2: Handler<S, E, Output = Self::Output> { ... }
fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
where Self: Sized,
Self::Output: Try,
H2: Handler<S, E, Output = Self::Output> { ... }
fn try_or_unmatched(self) -> TryOrUnmatched<Self>
where Self: Sized,
Self::Output: Try { ... }
fn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
where Self: Sized,
Self::Output: Context<O, D>,
C: Clone + Display + Send + Sync + 'static { ... }
fn expect<M>(self, message: M) -> Expect<Self, M>
where Self: Sized,
Self::Output: Try,
M: Display { ... }
fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
where Self: Sized,
R: RangeBounds<usize> { ... }
fn by_ref(&mut self) -> ByRef<'_, Self>
where Self: Sized { ... }
}
Expand description
A composable event handler.
This trait describes types that react to WLAN tap driver events. Such types can be composed in
a similar manner to the standard Iterator
trait using adapter and combinator functions.
Most Handler
functions resemble those found in Iterator
, Option
, and Result
.
The primary method implemented by event handlers is call
, which receives
an exclusive reference to some state (of the input type S
) and a shared reference to some
event (of the input type E
) and returns a Handled
that indicates whether or not the
handler matched the event and, if so, provides some output (of the type
Output
).
The matching of a handler with an event controls the routing and behavior of that handler. In
particular, branching combinators like and
, or
, try_and_then
, etc. execute handlers
based on whether or not the composed handlers have matched a given event.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Maps the output of the event handler using the given function.
Sourcefn and<H2>(self, handler: H2) -> And<Self, H2>
fn and<H2>(self, handler: H2) -> And<Self, H2>
Executes the handler followed by the given handler if and only if the event is matched by the first.
Sourcefn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
fn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
Executes the handler followed by the given handler if and only if the event is matched by the first and the output is not an error.
As with other try
functions, this function considers whether or not the handler matched
the event (Handled::Matched
vs. Handled::Unmatched
) and the output when matched
(output vs. error in Handled::Matched
). Both Handled::Unmatched
and Handled::Matched
with an error value are considered failures to handle an event.
Sourcefn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
Executes the handler followed by the given function if and only if the event is matched by the first. The function is given the output of the handler and must return a compatible handler to execute next.
Sourcefn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
fn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
Executes the handler followed by the given function if and only if the event is matched by the first and the output is not an error. The function is given the output of the handler and must return a compatible handler to execute next.
As with other try
functions, this function considers whether or not the handler matched
the event (Handled::Matched
vs. Handled::Unmatched
) and the output when matched
(output vs. error in Handled::Matched
). Both Handled::Unmatched
and Handled::Matched
with an error value are considered failures to handle an event.
Sourcefn or<H2>(self, handler: H2) -> Or<Self, H2>
fn or<H2>(self, handler: H2) -> Or<Self, H2>
Executes the handler followed by the given handler if and only if the event is not matched by the first.
Sourcefn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
Executes the handler followed by the given handler if the event is not matched by the first or the output is an error. That is, the given handler is executed only if the first fails: it does not match the event or it matches but returns an error.
As with other try
functions, this function considers whether or not the handler matched
the event (Handled::Matched
vs. Handled::Unmatched
) and the output when matched
(output vs. error in Handled::Matched
). Both Handled::Unmatched
and Handled::Matched
with an error value are considered failures to handle an event.
Sourcefn try_or_unmatched(self) -> TryOrUnmatched<Self>
fn try_or_unmatched(self) -> TryOrUnmatched<Self>
Combines the handler’s output with [try_or
] over Unmatched
.
This adapter terminates a chain of try
combinators such that the last handler’s output is
tried and, if it is unmatched or an error, Unmatched
is returned.
Sourcefn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
fn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
Provides context for fallible outputs (like Result
s).
Sourcefn expect<M>(self, message: M) -> Expect<Self, M>
fn expect<M>(self, message: M) -> Expect<Self, M>
Panics with the given message if a fallible output indicates an error.
Sourcefn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
Panics if the event handler does not match an event a number of times within the specified range.
The panic occurs as eagerly as possible, but may be deferred until the event handler is dropped if the number of matches is less than the lower bound of the range. Such a panic is disabled if the thread is already panicking.
Sourcefn by_ref(&mut self) -> ByRef<'_, Self>where
Self: Sized,
fn by_ref(&mut self) -> ByRef<'_, Self>where
Self: Sized,
Borrows the event handler (rather than consuming it).
This function is analogous to Iterator::by_ref
and can be used to apply adapters and
compositions to an event handler without consuming (moving) it. In particular, this is
useful when code cannot relinquish ownership of a handler and yet must adapt it, such as
methods that operate on a handler field through a reference.
Trait Implementations§
Source§impl<'h, S, E, O> Handler<S, E> for &'h mut dyn Handler<S, E, Output = O>
impl<'h, S, E, O> Handler<S, E> for &'h mut dyn Handler<S, E, Output = O>
Source§fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>
fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn and<H2>(self, handler: H2) -> And<Self, H2>
fn and<H2>(self, handler: H2) -> And<Self, H2>
Source§fn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
fn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
Source§fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
Source§fn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
fn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
Source§fn or<H2>(self, handler: H2) -> Or<Self, H2>
fn or<H2>(self, handler: H2) -> Or<Self, H2>
Source§fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
Source§fn try_or_unmatched(self) -> TryOrUnmatched<Self>
fn try_or_unmatched(self) -> TryOrUnmatched<Self>
Source§fn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
fn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
Result
s).Source§fn expect<M>(self, message: M) -> Expect<Self, M>
fn expect<M>(self, message: M) -> Expect<Self, M>
Source§fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
Source§impl<'h, S, E, O> Handler<S, E> for Box<dyn Handler<S, E, Output = O> + 'h>
impl<'h, S, E, O> Handler<S, E> for Box<dyn Handler<S, E, Output = O> + 'h>
Source§fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>
fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn and<H2>(self, handler: H2) -> And<Self, H2>
fn and<H2>(self, handler: H2) -> And<Self, H2>
Source§fn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
fn try_and<H2>(self, handler: H2) -> TryAnd<Self, H2>
Source§fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
Source§fn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
fn try_and_then<H2, F>(self, f: F) -> TryAndThen<Self, F>
Source§fn or<H2>(self, handler: H2) -> Or<Self, H2>
fn or<H2>(self, handler: H2) -> Or<Self, H2>
Source§fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
Source§fn try_or_unmatched(self) -> TryOrUnmatched<Self>
fn try_or_unmatched(self) -> TryOrUnmatched<Self>
Source§fn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
fn context<C, O, D>(self, context: C) -> Context<Self, C, O, D>
Result
s).