meio_extra/
custom_action.rs1use anyhow::Error;
4use async_trait::async_trait;
5use meio::handlers::{Handler, Priority};
6use meio::prelude::{Actor, Context};
7
8pub trait CustomAction: Send + 'static {}
12
13#[async_trait]
15pub trait CustomActionHandler<I: CustomAction>: Actor {
16 async fn handle(&mut self, input: I, _ctx: &mut Context<Self>) -> Result<(), Error>;
18}
19
20struct CustomActionHandlerImpl<I> {
26 input: Option<I>,
27}
28
29#[async_trait]
31impl<A, I> Handler<A> for CustomActionHandlerImpl<I>
32where
33 A: CustomActionHandler<I>,
34 I: CustomAction,
35{
36 fn priority(&self) -> Priority {
37 Priority::Normal
38 }
39
40 async fn handle(&mut self, actor: &mut A, ctx: &mut Context<A>) -> Result<(), Error> {
41 let input = self.input.take().expect("action handler called twice");
42 actor.handle(input, ctx).await
43 }
44}