pub struct ActorWeak<T: Actor> { /* private fields */ }Expand description
A weak, type-safe reference to an actor of type T.
ActorWeak<T> is a weak reference that does not prevent the actor from being dropped
and can be upgraded to a strong ActorRef<T> if the actor is still alive.
Like ActorRef<T>, it maintains compile-time type safety for the actor type T.
§Creating ActorWeak<T>
ActorWeak<T> instances are created by calling downgrade on an
existing ActorRef<T>:
let weak_ref = actor_ref.downgrade();§Upgrading to ActorRef<T>
An ActorWeak<T> can be upgraded to an ActorRef<T> using the upgrade method:
if let Some(strong_ref) = weak_ref.upgrade() {
// Successfully upgraded, actor is still alive
strong_ref.tell(MyMessage).await?;
} else {
// Actor is no longer alive
}Implementations§
Source§impl<T: Actor> ActorWeak<T>
impl<T: Actor> ActorWeak<T>
Sourcepub fn upgrade(&self) -> Option<ActorRef<T>>
pub fn upgrade(&self) -> Option<ActorRef<T>>
Attempts to upgrade the weak reference to a strong, type-safe reference.
Returns Some(ActorRef<T>) if the actor is still alive, or None if the actor
has been dropped.
Sourcepub fn identity(&self) -> Identity
pub fn identity(&self) -> Identity
Returns the unique ID of the actor this weak reference points to.
Sourcepub fn is_alive(&self) -> bool
pub fn is_alive(&self) -> bool
Checks if the actor might still be alive.
This method returns true if weak references can potentially be upgraded,
but does not guarantee that a subsequent upgrade call will succeed
due to potential race conditions.
Returns false if the actor is definitely dead (all strong references dropped).
Note: This is a heuristic check. For definitive actor state, always use
upgrade and check the returned Option.
Trait Implementations§
Source§impl<T: Actor + 'static> WeakActorControl for ActorWeak<T>
impl<T: Actor + 'static> WeakActorControl for ActorWeak<T>
Source§fn is_alive(&self) -> bool
fn is_alive(&self) -> bool
Source§fn upgrade(&self) -> Option<Box<dyn ActorControl>>
fn upgrade(&self) -> Option<Box<dyn ActorControl>>
None if the actor has been dropped.Source§fn clone_boxed(&self) -> Box<dyn WeakActorControl>
fn clone_boxed(&self) -> Box<dyn WeakActorControl>
Source§impl<T, M> WeakAskHandler<M, <T as Message<M>>::Reply> for ActorWeak<T>
impl<T, M> WeakAskHandler<M, <T as Message<M>>::Reply> for ActorWeak<T>
Source§fn upgrade(&self) -> Option<Box<dyn AskHandler<M, <T as Message<M>>::Reply>>>
fn upgrade(&self) -> Option<Box<dyn AskHandler<M, <T as Message<M>>::Reply>>>
None if the actor has been dropped.Source§fn clone_boxed(&self) -> Box<dyn WeakAskHandler<M, <T as Message<M>>::Reply>>
fn clone_boxed(&self) -> Box<dyn WeakAskHandler<M, <T as Message<M>>::Reply>>
Source§fn as_weak_control(&self) -> &dyn WeakActorControl
fn as_weak_control(&self) -> &dyn WeakActorControl
Source§impl<T, M> WeakTellHandler<M> for ActorWeak<T>
impl<T, M> WeakTellHandler<M> for ActorWeak<T>
Source§fn upgrade(&self) -> Option<Box<dyn TellHandler<M>>>
fn upgrade(&self) -> Option<Box<dyn TellHandler<M>>>
None if the actor has been dropped.