pub struct Mailbox<A: Actor> { /* private fields */ }
Expand description
A mailbox is the object that makes it possible to send a message to an actor.
It is lightweight to clone.
The actor holds its Inbox
counterpart.
The mailbox can accept:
- Regular messages wrapped in envelopes. Their type depend on the actor and is defined when
implementing the actor trait. (See [
Envelope
]) - Commands (See
Command
). Commands have a higher priority than messages: whenever a command is available, it is guaranteed to be processed as soon as possible regardless of the presence of pending regular messages.
If all mailboxes are dropped, the actor will process all of the pending messages
and gracefully exit with crate::actor::ActorExitStatus::Success
.
Implementations§
Source§impl<A: Actor> Mailbox<A>
impl<A: Actor> Mailbox<A>
pub fn actor_instance_id(&self) -> &str
Sourcepub async fn send_message<M>(
&self,
message: M,
) -> Result<Receiver<A::Reply>, SendError>
pub async fn send_message<M>( &self, message: M, ) -> Result<Receiver<A::Reply>, SendError>
Sends a message to the actor owning the associated inbox.
From an actor context, use the ActorContext::send_message
method instead.
SendError is returned if the actor has already exited.
pub async fn send_command(&self, command: Command) -> Result<(), SendError>
Sourcepub async fn ask<M, T>(&self, message: M) -> Result<T, AskError<Infallible>>
pub async fn ask<M, T>(&self, message: M) -> Result<T, AskError<Infallible>>
Similar to send_message
, except this method
waits asynchronously for the actor reply.
From an actor context, use the ActorContext::ask
method instead.
Sourcepub async fn ask_for_res<M, T, E: Debug>(
&self,
message: M,
) -> Result<T, AskError<E>>
pub async fn ask_for_res<M, T, E: Debug>( &self, message: M, ) -> Result<T, AskError<E>>
Similar to send_message
, except this method
waits asynchronously for the actor reply.
From an actor context, use the ActorContext::ask
method instead.
Trait Implementations§
impl<A: Actor> Eq for Mailbox<A>
Auto Trait Implementations§
impl<A> Freeze for Mailbox<A>
impl<A> RefUnwindSafe for Mailbox<A>
impl<A> Send for Mailbox<A>
impl<A> Sync for Mailbox<A>
impl<A> Unpin for Mailbox<A>
impl<A> UnwindSafe for Mailbox<A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.