use puppet::{puppet_actor, ActorMailbox, Message}; pub struct AppenderService { seen_data: Vec, } #[puppet_actor] impl AppenderService where // The additional `Send` and `'static` bounds are required due to the nature // of the actor running as a tokio task which has it's own requirements. T: Clone + Send + 'static, { fn new() -> Self { Self { seen_data: Vec::new(), } } #[puppet] async fn on_append_and_return(&mut self, msg: AppendAndReturn) -> Vec { self.seen_data.push(msg.value); self.seen_data.clone() } } #[derive(Clone)] pub struct AppendAndReturn { value: T, } impl Message for AppendAndReturn where T: Clone, { type Output = Vec; } #[tokio::test] async fn run_basic_actor() { let actor = AppenderService::::new(); let mailbox: ActorMailbox> = actor.spawn_actor().await; let message = AppendAndReturn { value: "Harri".to_string(), }; for _ in 0..3 { let response = mailbox.send(message.clone()).await; println!("Got values: {:?}", response); } }