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