Address API
Send messages to actors and check their status.
Addr<A>
The Addr type is a handle to send messages to an actor. It's cheap to clone and can be passed between actors.
Addr implements Clone, so you can freely share addresses between actors.
Request-Response
pub async fn send<M>(&self, msg: M) -> Result<M::Result, MailboxError>Send a message and wait for the response. Blocks until the handler returns.
Returns: Result<M::Result, MailboxError>
Where: A: Handler<M>, M: Message
pub async fn send_timeout<M>(&self, msg: M, timeout: Duration) -> Result<M::Result, MailboxError>Send a message with a timeout. Returns MailboxError::Timeout if no response within the duration.
Returns: Result<M::Result, MailboxError>
Where: A: Handler<M>, M: Message
pub async fn send_async<M>(&self, msg: M) -> Result<M::Result, MailboxError>Send to an AsyncHandler and wait for response.
Returns: Result<M::Result, MailboxError>
Where: A: AsyncHandler<M>, M: Message
Fire-and-Forget
pub async fn do_send<M>(&self, msg: M) -> Result<(), MailboxError>Send a message without waiting for a response. Waits for mailbox space if full.
Returns: Result<(), MailboxError>
Where: A: Handler<M>, M: Message
pub async fn do_send_async<M>(&self, msg: M) -> Result<(), MailboxError>Fire-and-forget for AsyncHandler.
Returns: Result<(), MailboxError>
Where: A: AsyncHandler<M>, M: Message
pub fn try_send<M>(&self, msg: M) -> Result<(), MailboxError>Non-blocking send. Returns immediately with MailboxFull if mailbox is at capacity.
Returns: Result<(), MailboxError>
Where: A: Handler<M>, M: Message
pub fn try_send_async<M>(&self, msg: M) -> Result<(), MailboxError>Non-blocking send for AsyncHandler.
Returns: Result<(), MailboxError>
Where: A: AsyncHandler<M>, M: Message
Status
pub fn id(&self) -> ActorIdGet the actor's unique identifier.
Returns: ActorId
pub fn is_alive(&self) -> boolCheck if the actor is still running. Returns false if the actor has stopped.
Returns: bool
Method Comparison
| Method | Waits for Response | Blocking | Use Case |
|---|---|---|---|
| send | Yes | Async await | Query data, request-response |
| send_timeout | Yes (with limit) | Async await | Requests with deadlines |
| do_send | No | Async (mailbox) | Commands, notifications |
| try_send | No | Never | Broadcasting, non-critical |
