1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::custom_action::*;
use anyhow::Error;
use async_trait::async_trait;
use meio::prelude::{Actor, Context};
#[async_trait]
trait ExtendedHandler: Actor {
async fn handle(&mut self, value: u8, ctx: &mut Context<Self>) -> Result<(), Error>;
async fn done(&mut self, ctx: &mut Context<Self>) -> Result<(), Error>;
}
struct ExtendedAction {
inner_value: Option<u8>,
}
impl CustomAction for ExtendedAction {}
#[async_trait]
impl<T: Actor> CustomActionHandler<ExtendedAction> for T
where
T: ExtendedHandler,
{
async fn handle(
&mut self,
input: ExtendedAction,
ctx: &mut Context<Self>,
) -> Result<(), Error> {
if let Some(value) = input.inner_value {
ExtendedHandler::handle(self, value, ctx).await
} else {
ExtendedHandler::done(self, ctx).await
}
}
}