pub trait ActorControl: Send + Sync {
// Required methods
fn identity(&self) -> Identity;
fn is_alive(&self) -> bool;
fn stop(&self) -> BoxFuture<'_, ()>;
fn kill(&self);
fn wait_stopped(&self) -> BoxFuture<'_, ()>;
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<'_, ()>
fn stop(&self) -> BoxFuture<'_, ()>
Gracefully stops the actor.
The actor will process all remaining messages in its mailbox before stopping. Idempotent: a closed mailbox is treated as “stop already in flight”.
The returned future resolves once the stop signal is enqueued, not
when the actor has finished stopping. To observe completion, follow up
with wait_stopped. Enqueueing awaits mailbox
admission, so on a full mailbox the future does not resolve until a
slot frees up — and a self-stop from inside the actor’s own handler on
a full mailbox can never be admitted (the loop that would free a slot
is parked awaiting that handler). With the deadlock-detection feature
enabled, that self-stop panics instead of hanging; see
ActorRef::stop.
Sourcefn kill(&self)
fn kill(&self)
Immediately terminates the actor.
Any messages still queued in the mailbox are discarded without being
processed (the physical drain happens after on_stop(killed = true)
returns). First signal wins: if a graceful
stop has already been dequeued, the actor completes that graceful stop
(draining its mailbox) and this kill is never observed — and a handler
already executing always runs to completion first; see
ActorRef::kill for the full semantics.
Idempotent: a closed or full terminate channel is treated as
“termination already in flight”.
Sourcefn wait_stopped(&self) -> BoxFuture<'_, ()>
fn wait_stopped(&self) -> BoxFuture<'_, ()>
Resolves once the actor has fully stopped (its runtime loop exited and the mailbox closed). Returns immediately if the actor already stopped.
Type-erased counterpart of
ActorRef::wait_stopped; it signals
completion only and cannot return the actor’s
ActorResult.
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.
Trait Implementations§
Source§impl Clone for Box<dyn ActorControl>
impl Clone for Box<dyn ActorControl>
Source§impl Debug for dyn ActorControl + '_
impl Debug for dyn ActorControl + '_
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".