Address

Struct Address 

Source
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: Pid

Implementations§

Source§

impl<S> Address<S>
where S: Puppet,

Source

pub fn get_status(&self) -> PuppetStatus

Returns the current lifecycle status of the puppet.

§Example Usage
let status = address.get_status();
Source

pub fn subscribe_status(&self) -> Receiver<PuppetStatus>

Subscribes to changes in the puppet’s lifecycle status.

Returns a watch::Receiver that can be used to receive status change notifications.

§Example Usage
let status_rx = address.status_subscribe();
Source

pub fn on_status_change<F>(&self, f: F)
where F: Fn(PuppetStatus) + Send + 'static,

Registers a callback function to be invoked when the puppet’s status changes.

The provided callback function will be executed asynchronously whenever the puppet’s lifecycle status changes.

§Example Usage
address.on_status_change(|status| {
    println!("Puppet status changed: {:?}", status);
});
Source

pub fn send<E>(&self, message: E) -> Result<(), PostmanError>
where S: Handler<E>, E: Message + 'static,

Sends a message of type E to the puppet.

Returns a Result indicating the success or failure of the send operation.

§Errors

Returns a PostmanError if the message fails to send.

§Example Usage
let result = address.send(MyMessage::new()).await;
Source

pub async fn ask<E>( &self, message: E, ) -> Result<ResponseFor<S, E>, PostmanError>
where S: Handler<E>, E: Message + 'static,

Sends a message of type E to the puppet 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.

§Example Usage
let response = address.ask(MyMessage::new()).await?;
Source

pub async fn ask_with_timeout<E>( &self, message: E, duration: Duration, ) -> Result<ResponseFor<S, E>, PostmanError>
where S: Handler<E>, E: Message + 'static,

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?;
Source

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§

Source§

impl<S> Clone for Address<S>
where S: Puppet + Clone,

Source§

fn clone(&self) -> Address<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Puppet> Debug for Address<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P> Display for Address<P>
where P: Puppet,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Message for T
where T: Debug + Send + 'static,

Source§

impl<T> Puppetable for T
where T: Send + Sync + Clone + 'static,