[][src]Struct acteur::ServiceAssistant

pub struct ServiceAssistant<S: Service> { /* fields omitted */ }

This object is provided to the handle method in the Receive trait for each message that an Actor receives. The Actor's assistant allows to send messages and to execute some task over the system.

use acteur::{Acteur, Service, Listen, ServiceConfiguration, ServiceAssistant};

#[derive(Debug)]
struct EmployeeTaxesCalculator {
    tax_rate: f32,
}

#[async_trait::async_trait]
impl Service for EmployeeTaxesCalculator {
    async fn initialize(system: &ServiceAssistant<Self>) -> (Self, ServiceConfiguration) {
        let service = EmployeeTaxesCalculator {
            tax_rate: 0.21,
        };

        let service_conf = ServiceConfiguration::default();

        (service, service_conf)
    }
}

#[derive(Debug)]
struct EmployeeSalaryChange(u32);

#[async_trait::async_trait]
impl Listen<EmployeeSalaryChange> for EmployeeTaxesCalculator {

    async fn handle(&self, message: EmployeeSalaryChange, system: &ServiceAssistant<Self>) {
        system.stop_system();
    }
}

Implementations

impl<S: Service> ServiceAssistant<S>[src]

pub async fn send_to_actor<'_, A: Actor + Receive<M>, M: Debug + Send + 'static>(
    &'_ self,
    actor_id: A::Id,
    message: M
)
[src]

Sends a message to the Actor with the specified Id. If the Actor is not loaded, it will load the actor before, calling its method activate

pub async fn call_actor<'_, '_, A: Actor + Respond<M>, M: Debug + Send + 'static>(
    &'_ self,
    actor_id: A::Id,
    message: M
) -> Result<<A as Respond<M>>::Response, &'_ str>
[src]

Sends a message to the Actor with the specified Id and waits the actor's response . If the Actor is not loaded, it will load the actor before, calling its method activate

pub async fn send_to_service<'_, S1: Service + Listen<M>, M: Debug + Send + 'static>(
    &'_ self,
    message: M
)
[src]

Sends a message to a Service. If the Service is not loaded, it will load the service before, calling its method initialize

pub async fn call_service<'_, '_, S1: Service + Serve<M>, M: Debug + Send + 'static>(
    &'_ self,
    message: M
) -> Result<<S1 as Serve<M>>::Response, &'_ str>
[src]

Sends a message to a Service and waits for its response. If the Service is not loaded, it will load the service before, calling its method initialize

pub fn stop_system(&self)[src]

Send an stop message to all actors in the system. Actors will process all the enqued messages before stop

pub async fn subscribe<'_, M: Sync + Send + Debug + 'static>(&'_ self) where
    S: Service + Listen<M>, 
[src]

Trait Implementations

impl<S: Service> Clone for ServiceAssistant<S>[src]

impl<S: Service> Debug for ServiceAssistant<S>[src]

Auto Trait Implementations

impl<S> !RefUnwindSafe for ServiceAssistant<S>

impl<S> Send for ServiceAssistant<S>

impl<S> Sync for ServiceAssistant<S>

impl<S> Unpin for ServiceAssistant<S> where
    S: Unpin

impl<S> !UnwindSafe for ServiceAssistant<S>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,