Skip to main content

WeakAskHandler

Trait WeakAskHandler 

Source
pub trait WeakAskHandler<M: Send + 'static, R: Send + 'static>: Send + Sync {
    // Required methods
    fn upgrade(&self) -> Option<Box<dyn AskHandler<M, R>>>;
    fn clone_boxed(&self) -> Box<dyn WeakAskHandler<M, R>>;
    fn as_weak_control(&self) -> &dyn WeakActorControl;
    fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result;
}
Expand description

Weak handler for request-response messages (object-safe).

Unlike AskHandler, this does not keep the actor alive. Must call upgrade() to obtain a strong handler before sending messages.

§Example

let weak_handlers: Vec<Box<dyn WeakAskHandler<GetStatus, Status>>> = vec![
    ActorRef::downgrade(&actor_a).into(),
    ActorRef::downgrade(&actor_b).into(),
];

for handler in &weak_handlers {
    if let Some(strong) = handler.upgrade() {
        let status = strong.ask(GetStatus).await?;
        println!("Status: {:?}", status);
    }
}

Required Methods§

Source

fn upgrade(&self) -> Option<Box<dyn AskHandler<M, R>>>

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

Source

fn clone_boxed(&self) -> Box<dyn WeakAskHandler<M, R>>

Clone this handler into a new boxed instance.

Source

fn as_weak_control(&self) -> &dyn WeakActorControl

Returns a reference to WeakActorControl for lifecycle management.

Use this to access identity(), is_alive(), upgrade(), etc.

Source

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

Debug formatting support for trait objects.

Trait Implementations§

Source§

impl<M: Send + 'static, R: Send + 'static> Clone for Box<dyn WeakAskHandler<M, R>>

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<M: Send + 'static, R: Send + 'static> Debug for Box<dyn WeakAskHandler<M, R>>

Source§

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

Formats the value using the given formatter. Read more
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 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.

Implementors§

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,