Use the actix or xtra crates to define actors as structs implementing message handlers, then spawn them in a runtime to process messages asynchronously.
use actix::prelude::*;
struct MyActor;
impl Actor for MyActor {
type Context = Context<Self>;
}
impl Handler<String> for MyActor {
type Result = ();
fn handle(&mut self, msg: String, _ctx: &mut Self::Context) {
println!("Received: {}", msg);
}
}
fn main() {
let sys = System::new();
let addr = MyActor.start();
addr.do_send("Hello Actor".to_string());
sys.run().unwrap();
}