pub struct Addr<I: Interface> { /* private fields */ }
Expand description
The address of a Service
.
Addresses allow to send messages to a service that implements a corresponding
Interface
as long as the service is running.
Addresses can be freely cloned. When the last clone is dropped, the message channel of the service closes permanently, which signals to the service that it can shut down.
Implementations§
Source§impl<I: Interface> Addr<I>
impl<I: Interface> Addr<I>
Sourcepub fn send<M>(&self, message: M) -> <I::Response as MessageResponse>::Outputwhere
I: FromMessage<M>,
pub fn send<M>(&self, message: M) -> <I::Response as MessageResponse>::Outputwhere
I: FromMessage<M>,
Sends a message to the service and returns the response.
Depending on the message’s response behavior, this either returns a future resolving to the return value, or does not return anything for fire-and-forget messages. The communication channel with the service is unbounded, so backlogs could occur when sending too many messages.
Sending asynchronous messages can fail with Err(SendError)
if the service has shut down.
The result of asynchronous messages does not have to be awaited. The message will be
delivered and handled regardless:
Sourcepub fn recipient<M>(self) -> Recipient<M, I::Response>where
I: FromMessage<M>,
pub fn recipient<M>(self) -> Recipient<M, I::Response>where
I: FromMessage<M>,
Returns a handle that can receive a given message independent of the interface.
See Recipient
for more information and examples.