Skip to main content

obsidian/router/
handler.rs

1use crate::context::Context;
2use crate::error::ObsidianError;
3
4use async_trait::async_trait;
5use std::future::Future;
6
7pub type ContextResult<T = ObsidianError> = Result<Context, T>;
8
9#[async_trait]
10pub trait Handler: Send + Sync + 'static {
11    async fn call(&self, ctx: Context) -> ContextResult;
12}
13
14#[async_trait]
15impl<T, F> Handler for T
16where
17    T: Fn(Context) -> F + Send + Sync + 'static,
18    F: Future<Output = ContextResult> + Send + 'static,
19{
20    async fn call(&self, ctx: Context) -> ContextResult {
21        (self)(ctx).await
22    }
23}