Skip to main content

Handler

Trait Handler 

Source
pub trait Handler<Req, Res>:
    Send
    + Sync
    + 'static
where Req: Message + Send + 'static, Res: Message + Send + 'static,
{ type Body: Encodable<Res> + Send + 'static; // Required method fn call( &self, ctx: RequestContext, request: Req, ) -> BoxFuture<'static, ServiceResult<Self::Body>>; }
Expand description

Trait for unary RPC handlers (owned request type).

Handlers return a Response<Self::Body> where Body is any type Encodable as Res — typically Res itself. The happy path is Ok(res.into()).

Required Associated Types§

Source

type Body: Encodable<Res> + Send + 'static

The response body type. Typically Res, or any Encodable<Res> (e.g. MaybeBorrowed).

Required Methods§

Source

fn call( &self, ctx: RequestContext, request: Req, ) -> BoxFuture<'static, ServiceResult<Self::Body>>

Handle a unary RPC request.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, Fut, Req, Res, B> Handler<Req, Res> for FnHandler<F>
where F: Fn(RequestContext, Req) -> Fut + Send + Sync + 'static, Fut: Future<Output = ServiceResult<B>> + Send + 'static, Req: Message + Send + 'static, Res: Message + Send + 'static, B: Encodable<Res> + Send + 'static,

Source§

type Body = B