Skip to main content

WeakActorControl

Trait WeakActorControl 

Source
pub trait WeakActorControl: Send + Sync {
    // Required methods
    fn identity(&self) -> Identity;
    fn is_alive(&self) -> bool;
    fn upgrade(&self) -> Option<Box<dyn ActorControl>>;
    fn clone_boxed(&self) -> Box<dyn WeakActorControl>;
    fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result;
}
Expand description

Type-erased trait for actor lifecycle control with weak references.

Unlike ActorControl, this does not keep the actor alive. Must call upgrade() to obtain a strong control before performing lifecycle operations.

§Example

let weak_controls: Vec<Box<dyn WeakActorControl>> = vec![
    ActorRef::downgrade(&actor_a).into(),
    ActorRef::downgrade(&actor_b).into(),
];

for control in &weak_controls {
    if let Some(strong) = control.upgrade() {
        strong.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 might still be alive (heuristic, not guaranteed).

Source

fn upgrade(&self) -> Option<Box<dyn ActorControl>>

Attempts to upgrade to a strong control reference. Returns None if the actor has been dropped.

Source

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

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 WeakActorControl>

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 WeakActorControl>

Source§

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

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

impl<T: Actor + 'static> From<&ActorWeak<T>> for Box<dyn WeakActorControl>

Source§

fn from(actor_weak: &ActorWeak<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Actor + 'static> From<ActorWeak<T>> for Box<dyn WeakActorControl>

Source§

fn from(actor_weak: ActorWeak<T>) -> Self

Converts to this type from the input type.

Implementors§

Source§

impl<T: Actor + 'static> WeakActorControl for ActorWeak<T>