Skip to main content

ActorWeak

Struct ActorWeak 

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

Source

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.

Source

pub fn identity(&self) -> Identity

Returns the unique ID of the actor this weak reference points to.

Source

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> Clone for ActorWeak<T>

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<T: Debug + Actor> Debug for ActorWeak<T>

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, M> From<&ActorWeak<T>> for Box<dyn WeakAskHandler<M, <T as Message<M>>::Reply>>
where T: Actor + Message<M> + 'static, M: Send + 'static, <T as Message<M>>::Reply: Send + 'static,

Source§

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

Converts to this type from the input type.
Source§

impl<T, M> From<&ActorWeak<T>> for Box<dyn WeakTellHandler<M>>
where T: Actor + Message<M> + 'static, M: Send + 'static,

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

impl<T, M> From<ActorWeak<T>> for Box<dyn WeakAskHandler<M, <T as Message<M>>::Reply>>
where T: Actor + Message<M> + 'static, M: Send + 'static, <T as Message<M>>::Reply: Send + 'static,

Source§

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

Converts to this type from the input type.
Source§

impl<T, M> From<ActorWeak<T>> for Box<dyn WeakTellHandler<M>>
where T: Actor + Message<M> + 'static, M: Send + 'static,

Source§

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

Converts to this type from the input type.
Source§

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

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

impl<T, M> WeakAskHandler<M, <T as Message<M>>::Reply> for ActorWeak<T>
where T: Actor + Message<M> + 'static, M: Send + 'static, <T as Message<M>>::Reply: Send + 'static,

Source§

fn upgrade(&self) -> Option<Box<dyn AskHandler<M, <T as Message<M>>::Reply>>>

Attempts to upgrade to a strong handler. Returns None if the actor has been dropped.
Source§

fn clone_boxed(&self) -> Box<dyn WeakAskHandler<M, <T as Message<M>>::Reply>>

Clone this handler into a new boxed instance.
Source§

fn as_weak_control(&self) -> &dyn WeakActorControl

Returns a reference to WeakActorControl for lifecycle management. Read more
Source§

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

Debug formatting support for trait objects.
Source§

impl<T, M> WeakTellHandler<M> for ActorWeak<T>
where T: Actor + Message<M> + 'static, M: Send + 'static,

Source§

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

Attempts to upgrade to a strong handler. Returns None if the actor has been dropped.
Source§

fn clone_boxed(&self) -> Box<dyn WeakTellHandler<M>>

Clone this handler into a new boxed instance.
Source§

fn as_weak_control(&self) -> &dyn WeakActorControl

Returns a reference to WeakActorControl for lifecycle management. Read more
Source§

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

Debug formatting support for trait objects.

Auto Trait Implementations§

§

impl<T> Freeze for ActorWeak<T>

§

impl<T> RefUnwindSafe for ActorWeak<T>

§

impl<T> Send for ActorWeak<T>

§

impl<T> Sync for ActorWeak<T>

§

impl<T> Unpin for ActorWeak<T>

§

impl<T> UnwindSafe for ActorWeak<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more