Reactor

Trait Reactor 

Source
pub trait Reactor<T, S = ()> {
    type Response;
    type Error;

    // Required method
    fn react(
        &mut self,
        event: Timed<Event<T>>,
        context: Context<'_, S>,
    ) -> Result<Self::Response, Self::Error>;

    // Provided methods
    fn map_response<P, F>(self, f: F) -> MapResponse<Self, F>
       where Self: Sized,
             F: FnMut(Self::Response) -> P { ... }
    fn map_error<E, F>(self, f: F) -> MapError<Self, F>
       where Self: Sized,
             F: FnMut(Self::Error) -> E { ... }
    fn respond<P>(self, response: P) -> Respond<Self, P>
       where Self: Sized,
             P: Clone { ... }
    fn fail<E>(self, error: E) -> Fail<Self, E>
       where Self: Sized,
             E: Clone { ... }
    fn then<R>(self, reactor: R) -> Then<Self, R>
       where Self: Sized,
             T: Clone,
             R: Reactor<T, S> { ... }
    fn and<R>(self, reactor: R) -> And<Self, R>
       where Self: Sized,
             Self::Error: From<R::Error>,
             T: Clone,
             R: Reactor<T, S> { ... }
    fn or<R>(self, reactor: R) -> Or<Self, R>
       where Self: Sized,
             T: Clone,
             R: Reactor<T, S, Response = Self::Response> { ... }
    fn inspect<F>(
        self,
        f: F,
    ) -> impl Reactor<T, S, Response = Self::Response, Error = Self::Error>
       where Self: Sized,
             T: Clone,
             F: FnMut(&Timed<Event<T>>, &Result<Self::Response, Self::Error>) { ... }
}
Expand description

A type that reacts to timed Events.

A reactor is a function that responds to system and data events. Reactors are formed from combinators, which compose behaviors.

Required Associated Types§

Source

type Response

The output type of successful responses from the reactor.

Source

type Error

The error type of failed responses from the reactor.

Required Methods§

Source

fn react( &mut self, event: Timed<Event<T>>, context: Context<'_, S>, ) -> Result<Self::Response, Self::Error>

Reacts to a timed Event.

§Errors

Returns an [Error] if the reaction fails or the reactor cannot otherwise respond to the event. Errors conditions are defined by implementations.

Provided Methods§

Source

fn map_response<P, F>(self, f: F) -> MapResponse<Self, F>
where Self: Sized, F: FnMut(Self::Response) -> P,

Source

fn map_error<E, F>(self, f: F) -> MapError<Self, F>
where Self: Sized, F: FnMut(Self::Error) -> E,

Source

fn respond<P>(self, response: P) -> Respond<Self, P>
where Self: Sized, P: Clone,

Reacts with this reactor and then responds with the given response, regardless of this reactor’s output.

Source

fn fail<E>(self, error: E) -> Fail<Self, E>
where Self: Sized, E: Clone,

Reacts with this reactor and then fails with the given error, regardless of this reactor’s output.

Source

fn then<R>(self, reactor: R) -> Then<Self, R>
where Self: Sized, T: Clone, R: Reactor<T, S>,

Reacts with this reactor and then the given reactor (regardless of outputs).

The constructed reactor returns the output of the given (subsequent) reactor. See also the event::then function.

Source

fn and<R>(self, reactor: R) -> And<Self, R>
where Self: Sized, Self::Error: From<R::Error>, T: Clone, R: Reactor<T, S>,

Reacts with this reactor and then the given reactor if and only if this reactor returns Ok.

The constructed reactor returns either an error from this reactor or the output of the given (subsequent) reactor. See also the event::and function.

Source

fn or<R>(self, reactor: R) -> Or<Self, R>
where Self: Sized, T: Clone, R: Reactor<T, S, Response = Self::Response>,

Reacts with this reactor and then the given reactor if and only if this reactor returns Err.

The constructed reactor returns either a response from this reactor or the output of the given (subsequent) reactor. See also the event::or function.

Source

fn inspect<F>( self, f: F, ) -> impl Reactor<T, S, Response = Self::Response, Error = Self::Error>
where Self: Sized, T: Clone, F: FnMut(&Timed<Event<T>>, &Result<Self::Response, Self::Error>),

Constructs a Reactor that inspects the event and output of self with the given function.

Implementors§

Source§

impl<T, S, E, R> Reactor<T, S> for Fail<R, E>
where E: Clone, R: Reactor<T, S>,

Source§

type Response = <R as Reactor<T, S>>::Response

Source§

type Error = E

Source§

impl<T, S, P, R> Reactor<T, S> for Respond<R, P>
where P: Clone, R: Reactor<T, S>,

Source§

type Response = P

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<T, S, R1, R2> Reactor<T, S> for And<R1, R2>
where T: Clone, R1: Reactor<T, S>, R1::Error: From<R2::Error>, R2: Reactor<T, S>,

Source§

type Response = <R2 as Reactor<T, S>>::Response

Source§

type Error = <R1 as Reactor<T, S>>::Error

Source§

impl<T, S, R1, R2> Reactor<T, S> for Or<R1, R2>
where T: Clone, R1: Reactor<T, S>, R2: Reactor<T, S, Response = R1::Response>,

Source§

type Response = <R1 as Reactor<T, S>>::Response

Source§

type Error = <R2 as Reactor<T, S>>::Error

Source§

impl<T, S, R1, R2> Reactor<T, S> for Then<R1, R2>
where T: Clone, R1: Reactor<T, S>, R2: Reactor<T, S>,

Source§

type Response = <R2 as Reactor<T, S>>::Response

Source§

type Error = <R2 as Reactor<T, S>>::Error

Source§

impl<T, S, R> Reactor<T, S> for AndChain<Dynamic<Vec<R>>>
where T: Clone, R: Reactor<T, S>,

Source§

type Response = Vec<<R as Reactor<T, S>>::Response>

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<T, S, R> Reactor<T, S> for OrChain<Dynamic<Vec<R>>>
where T: Clone, R: Reactor<T, S>,

Source§

type Response = <R as Reactor<T, S>>::Response

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<T, S, R> Reactor<T, S> for ThenChain<Dynamic<Vec<R>>>
where T: Clone, R: Reactor<T, S>,

Source§

type Response = <R as Reactor<T, S>>::Response

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<T, S, R, E, F> Reactor<T, S> for F
where F: FnMut(Timed<Event<T>>, Context<'_, S>) -> Result<R, E>,

Source§

impl<T, S, R, F> Reactor<T, S> for Inspect<R, F>
where T: Clone, R: Reactor<T, S>, F: FnMut(&Timed<Event<T>>, &Result<R::Response, R::Error>),

Source§

type Response = <R as Reactor<T, S>>::Response

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<T, S, R, O, F> Reactor<T, S> for MapError<R, F>
where R: Reactor<T, S>, F: FnMut(R::Error) -> O,

Source§

type Response = <R as Reactor<T, S>>::Response

Source§

type Error = O

Source§

impl<T, S, R, O, F> Reactor<T, S> for MapResponse<R, F>
where R: Reactor<T, S>, F: FnMut(R::Response) -> O,

Source§

type Response = O

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<T, S, U, R> Reactor<T, U> for WithState<R, S>
where R: Reactor<T, S>,

Source§

type Response = <R as Reactor<T, S>>::Response

Source§

type Error = <R as Reactor<T, S>>::Error

Source§

impl<U, S, R, O, F> Reactor<U, S> for FilterMapDataRecord<R, F>
where R: Reactor<O, S>, F: FnMut(U, Context<'_, S>) -> Option<O>,

Source§

type Response = Option<<R as Reactor<O, S>>::Response>

Source§

type Error = <R as Reactor<O, S>>::Error