use async_trait::async_trait;
use crate::{Context, RuntimedReplyHandle, RuntimedService};
#[async_trait]
pub trait Handler<M>
where
Self: RuntimedService + Sized,
M: Message,
{
async fn handle(&mut self, message: M, ctx: &mut Context<Self>) -> M::Result;
async fn handle_preferred(
&mut self,
message: M,
ctx: &mut Context<Self>,
handle: RuntimedReplyHandle<M, Self::Runtime>,
) where
M: Send + 'static,
M::Result: Send,
{
let res = self.handle(message, ctx).await;
let _ = handle.send(res);
}
}
pub trait Message: Send + 'static {
type Result: Send;
}