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§
Sourcefn tell(&self, msg: M) -> BoxFuture<'_, Result<()>>
fn tell(&self, msg: M) -> BoxFuture<'_, Result<()>>
Sends a message without waiting for a reply.
Sourcefn tell_with_timeout(
&self,
msg: M,
timeout: Duration,
) -> BoxFuture<'_, Result<()>>
fn tell_with_timeout( &self, msg: M, timeout: Duration, ) -> BoxFuture<'_, Result<()>>
Sends a message with timeout.
Sourcefn blocking_tell(&self, msg: M, timeout: Option<Duration>) -> Result<()>
fn blocking_tell(&self, msg: M, timeout: Option<Duration>) -> Result<()>
Blocking version of tell.
timeout: None blocks indefinitely until the message is admitted;
timeout: Some(duration) guarantees bounded waiting. The execution
mechanism (and its overhead) depends on the calling context — see
ActorRef::blocking_tell for the
authoritative “Execution paths” breakdown.
§Panics
Panics only when the mailbox is full (the try_send hot path never
blocks): from inside a LocalSet running on a multi-thread runtime,
or from an async context that cannot block — a task on a
current_thread runtime or a thread driving a current_thread
runtime’s block_on (see
ActorRef::blocking_tell for both
conditions).
Sourcefn clone_boxed(&self) -> Box<dyn TellHandler<M>>
fn clone_boxed(&self) -> Box<dyn TellHandler<M>>
Clone this handler into a new boxed instance.
Sourcefn downgrade(&self) -> Box<dyn WeakTellHandler<M>>
fn downgrade(&self) -> Box<dyn WeakTellHandler<M>>
Downgrade to a weak handler.
Sourcefn as_control(&self) -> &dyn ActorControl
fn as_control(&self) -> &dyn ActorControl
Returns a reference to ActorControl for lifecycle management.
Use this to access identity(), is_alive(), stop(), kill(), etc.
Trait Implementations§
Source§impl<M: Send + 'static> Debug for dyn TellHandler<M> + '_
impl<M: Send + 'static> Debug for dyn TellHandler<M> + '_
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".