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§

source

type Output

The output of the event handler when it is matched.

Required Methods§

source

fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>

Reacts to an event with some state.

Returns a Handled that indicates whether or not the handler matched the given event.

Provided Methods§

source

fn map<U, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> U,

Maps the output of the event handler using the given function.

source

fn and<H2>(self, handler: H2) -> And<Self, H2>
where Self: Sized, H2: Handler<S, E>,

Executes the handler followed by the given handler if and only if the event is matched by the first.

source

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>,

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.

source

fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
where Self: Sized, H2: Handler<S, E>, F: FnMut(Self::Output) -> H2,

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.

source

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,

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.

source

fn or<H2>(self, handler: H2) -> Or<Self, H2>
where Self: Sized, H2: Handler<S, E, Output = Self::Output>,

Executes the handler followed by the given handler if and only if the event is not matched by the first.

source

fn try_or<H2>(self, handler: H2) -> TryOr<Self, H2>
where Self: Sized, Self::Output: Try, H2: Handler<S, E, Output = Self::Output>,

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.

source

fn try_or_unmatched(self) -> TryOrUnmatched<Self>
where Self: Sized, Self::Output: Try,

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.

source

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,

Provides context for fallible outputs (like Results).

source

fn expect<M>(self, message: M) -> Expect<Self, M>
where Self: Sized, Self::Output: Try, M: Display,

Panics with the given message if a fallible output indicates an error.

source

fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
where Self: Sized, R: RangeBounds<usize>,

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.

source

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>

§

type Output = O

The output of the event handler when it is matched.
source§

fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>

Reacts to an event with some state. Read more
source§

fn map<U, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> U,

Maps the output of the event handler using the given function.
source§

fn and<H2>(self, handler: H2) -> And<Self, H2>
where Self: Sized, H2: Handler<S, E>,

Executes the handler followed by the given handler if and only if the event is matched by the first.
source§

fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
where Self: Sized, H2: Handler<S, E>, F: FnMut(Self::Output) -> H2,

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.
source§

fn or<H2>(self, handler: H2) -> Or<Self, H2>
where Self: Sized, H2: Handler<S, E, Output = Self::Output>,

Executes the handler followed by the given handler if and only if the event is not matched by the first.
source§

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,

Provides context for fallible outputs (like Results).
source§

fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
where Self: Sized, R: RangeBounds<usize>,

Panics if the event handler does not match an event a number of times within the specified range. Read more
source§

fn by_ref(&mut self) -> ByRef<'_, Self>
where Self: Sized,

Borrows the event handler (rather than consuming it). Read more
source§

impl<'h, S, E, O> Handler<S, E> for Box<dyn Handler<S, E, Output = O> + 'h>

§

type Output = O

The output of the event handler when it is matched.
source§

fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>

Reacts to an event with some state. Read more
source§

fn map<U, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Output) -> U,

Maps the output of the event handler using the given function.
source§

fn and<H2>(self, handler: H2) -> And<Self, H2>
where Self: Sized, H2: Handler<S, E>,

Executes the handler followed by the given handler if and only if the event is matched by the first.
source§

fn and_then<H2, F>(self, f: F) -> AndThen<Self, F>
where Self: Sized, H2: Handler<S, E>, F: FnMut(Self::Output) -> H2,

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.
source§

fn or<H2>(self, handler: H2) -> Or<Self, H2>
where Self: Sized, H2: Handler<S, E, Output = Self::Output>,

Executes the handler followed by the given handler if and only if the event is not matched by the first.
source§

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,

Provides context for fallible outputs (like Results).
source§

fn expect_matches_times<R>(self, expected: R) -> ExpectMatchesTimes<Self, R>
where Self: Sized, R: RangeBounds<usize>,

Panics if the event handler does not match an event a number of times within the specified range. Read more
source§

fn by_ref(&mut self) -> ByRef<'_, Self>
where Self: Sized,

Borrows the event handler (rather than consuming it). Read more

Implementations on Foreign Types§

source§

impl<'h, S, E, O> Handler<S, E> for Box<dyn Handler<S, E, Output = O> + 'h>

§

type Output = O

source§

fn call(&mut self, state: &mut S, event: &E) -> Handled<Self::Output>

Implementors§

source§

impl<'h, H, S, E> Handler<S, E> for ByRef<'h, H>
where H: Handler<S, E>,

§

type Output = <H as Handler<S, E>>::Output

source§

impl<'h, S, E, O> Handler<S, E> for &'h mut dyn Handler<S, E, Output = O>

§

type Output = O

source§

impl<F, S, E, U> Handler<S, E> for F
where F: FnMut(&mut S, &E) -> Handled<U>,

§

type Output = U

source§

impl<H1, S, E, H2> Handler<S, E> for And<H1, H2>
where H1: Handler<S, E>, H2: Handler<S, E>,

§

type Output = <H2 as Handler<S, E>>::Output

source§

impl<H1, S, E, H2> Handler<S, E> for Or<H1, H2>
where H1: Handler<S, E>, H2: Handler<S, E, Output = H1::Output>,

§

type Output = <H2 as Handler<S, E>>::Output

source§

impl<H1, S, E, H2> Handler<S, E> for TryAnd<H1, H2>
where H1: Handler<S, E>, H1::Output: Try, H2: Handler<S, E>, H2::Output: Try<Residual = <H1::Output as Try>::Residual>,

§

type Output = <H2 as Handler<S, E>>::Output

source§

impl<H1, S, E, H2> Handler<S, E> for TryOr<H1, H2>
where H1: Handler<S, E>, H1::Output: Try, H2: Handler<S, E, Output = H1::Output>,

§

type Output = <H2 as Handler<S, E>>::Output

source§

impl<H1, S, E, H2, F> Handler<S, E> for AndThen<H1, F>
where H1: Handler<S, E>, H2: Handler<S, E>, F: FnMut(H1::Output) -> H2,

§

type Output = <H2 as Handler<S, E>>::Output

source§

impl<H1, S, E, H2, F> Handler<S, E> for TryAndThen<H1, F>
where H1: Handler<S, E>, H1::Output: Try, H2: Handler<S, E>, H2::Output: Try<Residual = <H1::Output as Try>::Residual>, F: FnMut(<H1::Output as Try>::Output) -> H2,

§

type Output = <H2 as Handler<S, E>>::Output

source§

impl<H, S, E> Handler<S, E> for TryOrUnmatched<H>
where H: Handler<S, E>, H::Output: Try,

§

type Output = <H as Handler<S, E>>::Output

source§

impl<H, S, E, C, O, D> Handler<S, E> for Context<H, C, O, D>
where H: Handler<S, E>, H::Output: Context<O, D>, C: Clone + Display + Send + Sync + 'static,

§

type Output = Result<O, Error>

source§

impl<H, S, E, M> Handler<S, E> for Expect<H, M>
where H: Handler<S, E>, H::Output: Try, M: Display,

§

type Output = <<H as Handler<S, E>>::Output as Try>::Output

source§

impl<H, S, E, R> Handler<S, E> for ExpectMatchesTimes<H, R>
where H: Handler<S, E>, R: RangeBounds<usize>,

§

type Output = <H as Handler<S, E>>::Output

source§

impl<H, S, E, U, F> Handler<S, E> for Map<H, F>
where H: Handler<S, E>, F: FnMut(H::Output) -> U,

§

type Output = U

source§

impl<S, E, H> Handler<S, E> for DynamicAnd<Vec<H>>
where H: Handler<S, E>,

§

type Output = <H as Handler<S, E>>::Output

source§

impl<S, E, H> Handler<S, E> for DynamicOr<Vec<H>>
where H: Handler<S, E>,

§

type Output = <H as Handler<S, E>>::Output

source§

impl<S, E, H> Handler<S, E> for DynamicTryAnd<Vec<H>>
where H: Handler<S, E>, H::Output: Try,

§

type Output = <H as Handler<S, E>>::Output

source§

impl<S, E, H> Handler<S, E> for DynamicTryOr<Vec<H>>
where H: Handler<S, E>, H::Output: Try,

§

type Output = <H as Handler<S, E>>::Output