pub trait Actor: HasMailbox + Send {
type Init: Send + 'static;
// Required methods
fn init(
init: Self::Init,
ctx: &mut Context<Self>,
) -> impl Future<Output = Self> + Send;
fn handle_message(
&mut self,
msg: Self::Message,
ctx: &mut Context<Self>,
) -> impl Future<Output = ()> + Send;
// Provided method
fn on_stop(
&mut self,
_ctx: &mut Context<Self>,
) -> impl Future<Output = ()> + Send { ... }
}Expand description
An asynchronous, Send-safe actor.
Implement this for actors whose state is Send. The runtime calls init once,
then loops calling handle_message for each message, and finally calls
on_stop before the task exits.
For !Send state use LocalActor. To also receive stream events use StreamActor.
Required Associated Types§
Required Methods§
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.