pub trait Middleware<M: Metadata>: Send + Sync + 'static {
    type Future: Future<Output = Option<Response>> + Send + 'static;
    type CallFuture: Future<Output = Option<Output>> + Send + 'static;

    // Provided methods
    fn on_request<F, X>(
        &self,
        request: Request,
        meta: M,
        next: F
    ) -> Either<Self::Future, X> 
       where F: Fn(Request, M) -> X + Send + Sync,
             X: Future<Output = Option<Response>> + Send + 'static { ... }
    fn on_call<F, X>(
        &self,
        call: Call,
        meta: M,
        next: F
    ) -> Either<Self::CallFuture, X> 
       where F: Fn(Call, M) -> X + Send + Sync,
             X: Future<Output = Option<Output>> + Send + 'static { ... }
}
Expand description

RPC middleware

Required Associated Types§

source

type Future: Future<Output = Option<Response>> + Send + 'static

A returned request future.

source

type CallFuture: Future<Output = Option<Output>> + Send + 'static

A returned call future.

Provided Methods§

source

fn on_request<F, X>( &self, request: Request, meta: M, next: F ) -> Either<Self::Future, X> where F: Fn(Request, M) -> X + Send + Sync, X: Future<Output = Option<Response>> + Send + 'static,

Method invoked on each request. Allows you to either respond directly (without executing RPC call) or do any additional work before and/or after processing the request.

source

fn on_call<F, X>( &self, call: Call, meta: M, next: F ) -> Either<Self::CallFuture, X> where F: Fn(Call, M) -> X + Send + Sync, X: Future<Output = Option<Output>> + Send + 'static,

Method invoked on each call inside a request.

Allows you to either handle the call directly (without executing RPC call).

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<M: Metadata, A: Middleware<M>, B: Middleware<M>> Middleware<M> for (A, B)

§

type Future = Either<<A as Middleware<M>>::Future, <B as Middleware<M>>::Future>

§

type CallFuture = Either<<A as Middleware<M>>::CallFuture, <B as Middleware<M>>::CallFuture>

source§

fn on_request<F, X>( &self, request: Request, meta: M, process: F ) -> Either<Self::Future, X> where F: Fn(Request, M) -> X + Send + Sync, X: Future<Output = Option<Response>> + Send + 'static,

source§

fn on_call<F, X>( &self, call: Call, meta: M, process: F ) -> Either<Self::CallFuture, X> where F: Fn(Call, M) -> X + Send + Sync, X: Future<Output = Option<Output>> + Send + 'static,

source§

impl<M: Metadata, A: Middleware<M>, B: Middleware<M>, C: Middleware<M>> Middleware<M> for (A, B, C)

§

type Future = Either<<A as Middleware<M>>::Future, Either<<B as Middleware<M>>::Future, <C as Middleware<M>>::Future>>

§

type CallFuture = Either<<A as Middleware<M>>::CallFuture, Either<<B as Middleware<M>>::CallFuture, <C as Middleware<M>>::CallFuture>>

source§

fn on_request<F, X>( &self, request: Request, meta: M, process: F ) -> Either<Self::Future, X> where F: Fn(Request, M) -> X + Send + Sync, X: Future<Output = Option<Response>> + Send + 'static,

source§

fn on_call<F, X>( &self, call: Call, meta: M, process: F ) -> Either<Self::CallFuture, X> where F: Fn(Call, M) -> X + Send + Sync, X: Future<Output = Option<Output>> + Send + 'static,

source§

impl<M: Metadata, A: Middleware<M>, B: Middleware<M>, C: Middleware<M>, D: Middleware<M>> Middleware<M> for (A, B, C, D)

§

type Future = Either<<A as Middleware<M>>::Future, Either<<B as Middleware<M>>::Future, Either<<C as Middleware<M>>::Future, <D as Middleware<M>>::Future>>>

§

type CallFuture = Either<<A as Middleware<M>>::CallFuture, Either<<B as Middleware<M>>::CallFuture, Either<<C as Middleware<M>>::CallFuture, <D as Middleware<M>>::CallFuture>>>

source§

fn on_request<F, X>( &self, request: Request, meta: M, process: F ) -> Either<Self::Future, X> where F: Fn(Request, M) -> X + Send + Sync, X: Future<Output = Option<Response>> + Send + 'static,

source§

fn on_call<F, X>( &self, call: Call, meta: M, process: F ) -> Either<Self::CallFuture, X> where F: Fn(Call, M) -> X + Send + Sync, X: Future<Output = Option<Output>> + Send + 'static,

Implementors§

source§

impl<M: Metadata> Middleware<M> for Noop

§

type Future = Pin<Box<dyn Future<Output = Option<Response>> + Send>>

§

type CallFuture = Pin<Box<dyn Future<Output = Option<Output>> + Send>>