Skip to main content

Handler

Trait Handler 

Source
pub trait Handler<TCtx, TInput, TOutput, TError>:
    Send
    + Sync
    + 'static {
    // Required method
    fn call(
        &self,
        ctx: TCtx,
        input: TInput,
    ) -> BoxFuture<'static, Result<TOutput, TError>>;
}
Expand description

Handler function signature. Auto-implemented for async fn with matching signature.

Prefer named async functions over closures for better type inference:

async fn list_planets(ctx: AppCtx, input: ListInput) -> Result<Vec<Planet>, ORPCError> { ... }
os.handler(list_planets)

Required Methods§

Source

fn call( &self, ctx: TCtx, input: TInput, ) -> BoxFuture<'static, Result<TOutput, TError>>

Implementors§

Source§

impl<F, Fut, TCtx, TInput, TOutput, TError> Handler<TCtx, TInput, TOutput, TError> for F
where F: Fn(TCtx, TInput) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<TOutput, TError>> + Send + 'static, TCtx: Send + 'static, TInput: Send + 'static, TOutput: Send + 'static, TError: Send + 'static,

Blanket impl for Fn(TCtx, TInput) -> Future<Output = Result<TOutput, TError>>.

This allows both named async fns and closures to be used as handlers.