Skip to main content

ActorControl

Trait ActorControl 

Source
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§

Source

fn identity(&self) -> Identity

Returns the unique identity of the actor.

Source

fn is_alive(&self) -> bool

Checks if the actor is still alive.

Source

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.

Source

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”.

Source

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.

Source

fn downgrade(&self) -> Box<dyn WeakActorControl>

Downgrades to a weak control reference.

Source

fn clone_boxed(&self) -> Box<dyn ActorControl>

Clone this control into a new boxed instance.

Source

fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result

Debug formatting support for trait objects.

Trait Implementations§

Source§

impl Clone for Box<dyn ActorControl>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for dyn ActorControl + '_

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Actor> From<&ActorRef<T>> for Box<dyn ActorControl>

Source§

fn from(actor_ref: &ActorRef<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Actor> From<ActorRef<T>> for Box<dyn ActorControl>

Source§

fn from(actor_ref: ActorRef<T>) -> Self

Converts to this type from the input type.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§