pub trait ActorControl: Send + Sync {
// Required methods
fn identity(&self) -> Identity;
fn is_alive(&self) -> bool;
fn stop(&self) -> BoxFuture<'_, Result<()>>;
fn kill(&self) -> Result<()>;
fn downgrade(&self) -> Box<dyn WeakActorControl>;
fn clone_boxed(&self) -> Box<dyn ActorControl>;
fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result;
}Expand description
Type-erased trait for actor lifecycle control with strong references.
This trait allows managing different actor types through a unified interface without knowing their message types. The handlers maintain strong references to actors, keeping them alive.
§Example
ⓘ
let controls: Vec<Box<dyn ActorControl>> = vec![
(&actor_a).into(),
(&actor_b).into(),
];
// Stop all actors
for control in &controls {
control.stop().await?;
}Required Methods§
Sourcefn stop(&self) -> BoxFuture<'_, Result<()>>
fn stop(&self) -> BoxFuture<'_, Result<()>>
Gracefully stops the actor.
The actor will process all remaining messages in its mailbox before stopping.
Sourcefn kill(&self) -> Result<()>
fn kill(&self) -> Result<()>
Immediately terminates the actor.
The actor will stop without processing remaining messages.
Sourcefn downgrade(&self) -> Box<dyn WeakActorControl>
fn downgrade(&self) -> Box<dyn WeakActorControl>
Downgrades to a weak control reference.
Sourcefn clone_boxed(&self) -> Box<dyn ActorControl>
fn clone_boxed(&self) -> Box<dyn ActorControl>
Clone this control into a new boxed instance.