ActorControl

Trait ActorControl 

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

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<'_, Result<()>>

Gracefully stops the actor.

The actor will process all remaining messages in its mailbox before stopping.

Source

fn kill(&self) -> Result<()>

Immediately terminates the actor.

The actor will stop without processing remaining messages.

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Box<dyn ActorControl>

Source§

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

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

impl<T: Actor + 'static> 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 + 'static> From<ActorRef<T>> for Box<dyn ActorControl>

Source§

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

Converts to this type from the input type.

Implementors§

Source§

impl<T: Actor + 'static> ActorControl for ActorRef<T>