pub trait Handler<M>: Actor {
type Return: Send + 'static;
// Required method
fn handle(
&mut self,
message: M,
ctx: &mut Context<Self>
) -> impl Future<Output = Self::Return> + Send;
}
Expand description
Defines that an Actor
can handle a given message M
.
§Example
struct Msg;
impl Handler<Msg> for MyActor {
type Return = u32;
async fn handle(&mut self, message: Msg, ctx: &mut Context<Self>) -> u32 {
20
}
}
fn main() {
smol::block_on(async {
let addr = xtra::spawn_smol(MyActor, Mailbox::unbounded());
assert_eq!(addr.send(Msg).await, Ok(20));
})
}
Required Associated Types§
Required Methods§
Object Safety§
This trait is not object safe.