Skip to main content

TellHandler

Trait TellHandler 

Source
pub trait TellHandler<M: Send + 'static>: Send + Sync {
    // Required methods
    fn tell(&self, msg: M) -> BoxFuture<'_, Result<()>>;
    fn tell_with_timeout(
        &self,
        msg: M,
        timeout: Duration,
    ) -> BoxFuture<'_, Result<()>>;
    fn blocking_tell(&self, msg: M, timeout: Option<Duration>) -> Result<()>;
    fn clone_boxed(&self) -> Box<dyn TellHandler<M>>;
    fn downgrade(&self) -> Box<dyn WeakTellHandler<M>>;
    fn as_control(&self) -> &dyn ActorControl;
    fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result;
}
Expand description

Fire-and-forget message handler for strong references (object-safe).

This trait allows storing different actor types that handle the same message type in a unified collection. The handlers maintain strong references to actors, keeping them alive.

§Example

let handlers: Vec<Box<dyn TellHandler<MyMessage>>> = vec![
    (&actor_a).into(),
    (&actor_b).into(),
];

for handler in &handlers {
    handler.tell(MyMessage { data: 42 }).await?;
}

Required Methods§

Source

fn tell(&self, msg: M) -> BoxFuture<'_, Result<()>>

Sends a message without waiting for a reply.

Source

fn tell_with_timeout( &self, msg: M, timeout: Duration, ) -> BoxFuture<'_, Result<()>>

Sends a message with timeout.

Source

fn blocking_tell(&self, msg: M, timeout: Option<Duration>) -> Result<()>

Blocking version of tell.

§Timeout Behavior
  • timeout: None: Uses Tokio’s blocking_send directly. Most efficient but blocks indefinitely.
  • timeout: Some(duration): Spawns a separate thread with a temporary runtime. Has overhead (~50-200μs for thread + ~1-10μs for runtime) but guarantees bounded waiting.
Source

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

Clone this handler into a new boxed instance.

Source

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

Downgrade to a weak handler.

Source

fn as_control(&self) -> &dyn ActorControl

Returns a reference to ActorControl for lifecycle management.

Use this to access identity(), is_alive(), stop(), kill(), etc.

Source

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

Debug formatting support for trait objects.

Trait Implementations§

Source§

impl<M: Send + 'static> Clone for Box<dyn TellHandler<M>>

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> Debug for Box<dyn TellHandler<M>>

Source§

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

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

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.

Implementors§

Source§

impl<T, M> TellHandler<M> for ActorRef<T>
where T: Actor + Message<M> + 'static, M: Send + 'static,