pub struct OutboundEnvelope { /* private fields */ }Expand description
Represents a message prepared for sending, including sender and optional recipient addresses.
An OutboundEnvelope is typically created by an agent (using methods like
AgentHandle::create_envelope)
before sending a message. It holds the MessageAddress of the sender (return_address)
and optionally the MessageAddress of the recipient (recipient_address).
The primary methods for dispatching the message are OutboundEnvelope::send (asynchronous)
and OutboundEnvelope::reply (synchronous wrapper).
Equality and hashing are based solely on the return_address.
Implementations§
Source§impl OutboundEnvelope
impl OutboundEnvelope
Sourcepub fn new(
return_address: MessageAddress,
cancellation_token: CancellationToken,
) -> Self
pub fn new( return_address: MessageAddress, cancellation_token: CancellationToken, ) -> Self
Creates a new OutboundEnvelope with only a return address specified.
The recipient address is initially set to None. Use OutboundEnvelope::send
or OutboundEnvelope::reply to send the message, typically back to the
return_address if no recipient is set later (though send_message_inner logic defaults to return_address if recipient_address is None).
§Arguments
return_address: TheMessageAddressof the agent creating this envelope (the sender).
§Returns
A new OutboundEnvelope instance.
Sourcepub fn reply_to(&self) -> MessageAddress
pub fn reply_to(&self) -> MessageAddress
Returns a clone of the sender’s MessageAddress.
Sourcepub fn recipient(&self) -> &Option<MessageAddress>
pub fn recipient(&self) -> &Option<MessageAddress>
Returns a reference to the optional recipient’s MessageAddress.
Sourcepub fn reply(
&self,
message: impl ActonMessage + 'static,
) -> Result<(), MessageError>
pub fn reply( &self, message: impl ActonMessage + 'static, ) -> Result<(), MessageError>
Sends a message using this envelope, blocking the current thread until sent.
Warning: This method spawns a blocking Tokio task and creates a new Tokio runtime
internally to execute the asynchronous send operation. This is generally discouraged
within an existing asynchronous context as it can lead to performance issues or deadlocks.
Prefer using the asynchronous OutboundEnvelope::send method whenever possible.
This method is primarily intended for scenarios where an asynchronous context is not readily available, but its use should be carefully considered.
§Arguments
message: The message payload to send. Must implementActonMessageand be'static.
§Returns
Ok(()): If the message was successfully scheduled to be sent (actual delivery depends on the recipient).Err(MessageError): Currently, this implementation always returnsOk(()), but the signature allows for future error handling. Potential errors (like closed channels) are logged internally.
Sourcepub async fn send(&self, message: impl ActonMessage + 'static)
pub async fn send(&self, message: impl ActonMessage + 'static)
Sends a message asynchronously using this envelope.
This method takes the message payload, wraps it in an Arc, and calls the
internal send_message_inner to dispatch it to the recipient’s channel.
The recipient is determined by recipient_address if Some, otherwise it
defaults to return_address.
This is the preferred method for sending messages from within an asynchronous context.
§Arguments
message: The message payload to send. Must implementActonMessageand be'static.
Trait Implementations§
Source§impl Clone for OutboundEnvelope
impl Clone for OutboundEnvelope
Source§fn clone(&self) -> OutboundEnvelope
fn clone(&self) -> OutboundEnvelope
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for OutboundEnvelope
impl Debug for OutboundEnvelope
Source§impl Hash for OutboundEnvelope
Implements hashing for OutboundEnvelope based on the return_address.
impl Hash for OutboundEnvelope
Implements hashing for OutboundEnvelope based on the return_address.
Source§impl PartialEq for OutboundEnvelope
Implements equality comparison for OutboundEnvelope based on the return_address.
impl PartialEq for OutboundEnvelope
Implements equality comparison for OutboundEnvelope based on the return_address.
impl Eq for OutboundEnvelope
Derives Eq based on the PartialEq implementation.
Auto Trait Implementations§
impl Freeze for OutboundEnvelope
impl RefUnwindSafe for OutboundEnvelope
impl Send for OutboundEnvelope
impl Sync for OutboundEnvelope
impl Unpin for OutboundEnvelope
impl UnwindSafe for OutboundEnvelope
Blanket Implementations§
Source§impl<T> ActonMessage for T
impl<T> ActonMessage for T
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§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.