pub trait Handler<M: 'static + Send>: Actor {
type Result: Send;
// Required method
fn handle<'life0, 'life1, 'async_trait>(
&'life0 mut self,
message: M,
context: &'life1 mut Context<Self>,
) -> Pin<Box<dyn Future<Output = Self::Result> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
Handler handles a certain type of message asyncronously.
§Example
use async_trait::async_trait;
use atomic_actor::*;
struct AddOne;
impl Actor for AddOne {
type Context = Context<Self>;
}
#[async_trait]
impl Handler<i32> for AddOne {
type Result = i32;
async fn handle(&mut self, message: i32, _: &mut Context<Self>) -> i32 {
message + 1
}
}
#[tokio::main]
async fn main() {
let addr = AddOne.start();
assert_eq!(addr.send(1).unwrap().await, 2);
}Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".