use actix::prelude::*; /// Define `Ping` message struct Ping(usize); impl Message for Ping { type Result = usize; } /// Actor struct MyActor { count: usize, } /// Declare actor and its context impl Actor for MyActor { type Context = Context; } /// Handler for `Ping` message impl Handler for MyActor { type Result = usize; fn handle(&mut self, msg: Ping, _: &mut Context) -> Self::Result { self.count += msg.0; self.count } } #[actix_rt::main] async fn main() { // start new actor let addr = MyActor { count: 10 }.start(); // send message and get future for result let res = addr.send(Ping(10)).await; // handle() returns tokio handle println!("RESULT: {}", res.unwrap() == 20); // stop system and exit System::current().stop(); }