pub struct Address<S>where
S: Puppet,{
pub pid: Pid,
/* private fields */
}Expand description
Represents an address to which messages can be sent to a puppet.
An Address is returned when spawning a puppet and provides a more efficient way
to send messages compared to using pptr.send(), as it involves one less layer of indirection.
§Example Usage
ⓘ
let address = pptr.spawn::<Master, Puppet>(builder).await?;
let status = address.get_status();Fields§
§pid: PidImplementations§
Source§impl<S> Address<S>where
S: Puppet,
impl<S> Address<S>where
S: Puppet,
Sourcepub fn get_status(&self) -> PuppetStatus
pub fn get_status(&self) -> PuppetStatus
Sourcepub fn subscribe_status(&self) -> Receiver<PuppetStatus>
pub fn subscribe_status(&self) -> Receiver<PuppetStatus>
Sourcepub fn on_status_change<F>(&self, f: F)
pub fn on_status_change<F>(&self, f: F)
Sourcepub fn send<E>(&self, message: E) -> Result<(), PostmanError>
pub fn send<E>(&self, message: E) -> Result<(), PostmanError>
Sourcepub async fn ask<E>(
&self,
message: E,
) -> Result<ResponseFor<S, E>, PostmanError>
pub async fn ask<E>( &self, message: E, ) -> Result<ResponseFor<S, E>, PostmanError>
Sourcepub async fn ask_with_timeout<E>(
&self,
message: E,
duration: Duration,
) -> Result<ResponseFor<S, E>, PostmanError>
pub async fn ask_with_timeout<E>( &self, message: E, duration: Duration, ) -> Result<ResponseFor<S, E>, PostmanError>
Sends a message of type E to the puppet with a timeout and awaits a response.
Returns a Result containing the response or an error.
§Errors
Returns a PostmanError if the message fails to send or receive a response within the timeout duration.
§Example Usage
ⓘ
let response = address.ask_with_timeout(MyMessage::new(), Duration::from_secs(5)).await?;Sourcepub async fn spawn<P>(&self, puppet: P) -> Result<Address<P>, PuppetError>where
P: Puppet,
pub async fn spawn<P>(&self, puppet: P) -> Result<Address<P>, PuppetError>where
P: Puppet,
Spawns a new puppet of type P using the provided PuppetBuilder and sets
the current puppet as the puppet’s master.
Returns an Address<P> for the newly spawned puppet.
§Errors
Returns a PuppetError if the puppet fails to spawn or initialize.
§Example Usage
ⓘ
let address = address.spawn::<Puppet>(builder).await?;Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Address<S>
impl<S> !RefUnwindSafe for Address<S>
impl<S> Send for Address<S>
impl<S> Sync for Address<S>
impl<S> Unpin for Address<S>
impl<S> !UnwindSafe for Address<S>
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
Mutably borrows from an owned value. Read more