Handler

Trait Handler 

Source
pub trait Handler<Args, State>: Clone {
    type Future: Future<Output = Result<Frame>> + Send + 'static;

    // Required method
    fn invoke(&self, frame: impl Into<Frame>, state: State) -> Self::Future;

    // Provided methods
    fn context(&self) -> ActionContext<State>
       where State: Send + Sync + 'static { ... }
    fn as_into_actionable(&self) -> BoxedAction<State>
       where Self: Clone + Send + Sync + 'static,
             Args: Clone + Send + Sync + 'static,
             State: Clone + Send + Sync + 'static { ... }
    fn into_stream(
        self,
        state: State,
    ) -> (impl Stream<Item = Result<Frame>>, FrameOutbox)
       where Self: Clone + Send + Sync + 'static,
             Args: Clone + Send + Sync + 'static,
             State: Clone + Send + Sync + 'static { ... }
    fn ready(self, state: State) -> ReadyAction<Self, Args, State>
       where Self: Clone + Send + 'static,
             Args: Clone + Send + 'static,
             State: Clone + Send + 'static { ... }
    fn candidate(self) -> CandidateAction<Self, Args, State>
       where Self: Clone + Send + 'static,
             Args: Clone + Send + 'static,
             State: Clone + Send + 'static { ... }
    fn active(self, state: State) -> ActiveAction
       where Self: Clone + Send + Sync + 'static,
             Args: Clone + Send + Sync + 'static,
             State: Clone + Send + Sync + 'static { ... }
}
Expand description

An action is an async function that can be turned into an frame handler.

Required Associated Types§

Source

type Future: Future<Output = Result<Frame>> + Send + 'static

Action futures must resolve into an Frame of some kind.

Required Methods§

Source

fn invoke(&self, frame: impl Into<Frame>, state: State) -> Self::Future

Invoke the action with a given frame and state, returning the frameual frame that will be produced by the action.

Provided Methods§

Source

fn context(&self) -> ActionContext<State>
where State: Send + Sync + 'static,

Poll for the action context. This is normally a service, but in some cases, it may be a frame handler or a router.

Source

fn as_into_actionable(&self) -> BoxedAction<State>
where Self: Clone + Send + Sync + 'static, Args: Clone + Send + Sync + 'static, State: Clone + Send + Sync + 'static,

Convert this action into a type erased actionable service.

Source

fn into_stream( self, state: State, ) -> (impl Stream<Item = Result<Frame>>, FrameOutbox)
where Self: Clone + Send + Sync + 'static, Args: Clone + Send + Sync + 'static, State: Clone + Send + Sync + 'static,

Use into_stream to turn the action into a stream and a stream handle. See [Actionable::into_stream] for more information.

Source

fn ready(self, state: State) -> ReadyAction<Self, Args, State>
where Self: Clone + Send + 'static, Args: Clone + Send + 'static, State: Clone + Send + 'static,

Use with_state to turn the action into a stateful action, which can be used as a tower::Service.

Source

fn candidate(self) -> CandidateAction<Self, Args, State>
where Self: Clone + Send + 'static, Args: Clone + Send + 'static, State: Clone + Send + 'static,

Create a Candidate actionable from the action, with the given state. Candidates can be “suspended” by boxing them for later.

Source

fn active(self, state: State) -> ActiveAction
where Self: Clone + Send + Sync + 'static, Args: Clone + Send + Sync + 'static, State: Clone + Send + Sync + 'static,

Create an Active actionable from the action, with the given state.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Handler<Frame, ()> for StatelessSystem

Source§

impl<Args, State> Handler<Args, State> for Endpoint<State>
where State: Clone + Send + 'static, Args: Clone + Send + 'static,

Source§

impl<Func, Future, State, Output> Handler<(), State> for Func
where Func: FnOnce() -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static,

Source§

impl<Func, Future, State, Output, A> Handler<(A,), State> for Func
where Func: FnOnce(A) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B> Handler<(A, B), State> for Func
where Func: FnOnce(A, B) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C> Handler<(A, B, C), State> for Func
where Func: FnOnce(A, B, C) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D> Handler<(A, B, C, D), State> for Func
where Func: FnOnce(A, B, C, D) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E> Handler<(A, B, C, D, E), State> for Func
where Func: FnOnce(A, B, C, D, E) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F> Handler<(A, B, C, D, E, F), State> for Func
where Func: FnOnce(A, B, C, D, E, F) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F, G> Handler<(A, B, C, D, E, F, G), State> for Func
where Func: FnOnce(A, B, C, D, E, F, G) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send, G: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F, G, H> Handler<(A, B, C, D, E, F, G, H), State> for Func
where Func: FnOnce(A, B, C, D, E, F, G, H) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send, G: Extractor<State> + Send, H: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F, G, H, I> Handler<(A, B, C, D, E, F, G, H, I), State> for Func
where Func: FnOnce(A, B, C, D, E, F, G, H, I) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send, G: Extractor<State> + Send, H: Extractor<State> + Send, I: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F, G, H, I, J> Handler<(A, B, C, D, E, F, G, H, I, J), State> for Func
where Func: FnOnce(A, B, C, D, E, F, G, H, I, J) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send, G: Extractor<State> + Send, H: Extractor<State> + Send, I: Extractor<State> + Send, J: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F, G, H, I, J, K> Handler<(A, B, C, D, E, F, G, H, I, J, K), State> for Func
where Func: FnOnce(A, B, C, D, E, F, G, H, I, J, K) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send, G: Extractor<State> + Send, H: Extractor<State> + Send, I: Extractor<State> + Send, J: Extractor<State> + Send, K: Extractor<State> + Send,

Source§

impl<Func, Future, State, Output, A, B, C, D, E, F, G, H, I, J, K, L> Handler<(A, B, C, D, E, F, G, H, I, J, K, L), State> for Func
where Func: FnOnce(A, B, C, D, E, F, G, H, I, J, K, L) -> Future + Clone + Send + 'static, State: Send + Sync + 'static, Output: Into<Frame>, Future: Future<Output = Output> + Send + 'static, A: Extractor<State> + Send, B: Extractor<State> + Send, C: Extractor<State> + Send, D: Extractor<State> + Send, E: Extractor<State> + Send, F: Extractor<State> + Send, G: Extractor<State> + Send, H: Extractor<State> + Send, I: Extractor<State> + Send, J: Extractor<State> + Send, K: Extractor<State> + Send, L: Extractor<State> + Send,

Source§

impl<State> Handler<Frame, State> for System<Open, State>
where State: Clone + Send + Sync + 'static,

Source§

impl<State> Handler<Frame, State> for StatefulSystem<State>
where State: Clone + Send + Sync + 'static,