pub struct Registry { /* private fields */ }
This is supported on crate features runtime-tokio or runtime-async-std only.
Expand description

Registry is an manager object providing access to the addresses of Actors that implement Service trait.

Registry maintains a list of spawned services and when an address of a service is requested, it checks whether the corresponding actor is already running. If so, address of this actor is returned. Otherwise, actor is spawned first.

Stopping and resuming

Services managed by the Registry may still be stopped via the Address::stop method. In that case, actor will not be resumed automatically, but it will be started again if its adress will be requested one more time.

Examples


#[derive(Default)] // Default trait is required for Registry to automatically creaate actor.
struct Ping;

#[async_trait]
impl Actor for Ping {}

#[async_trait]
impl Service for Ping {
    const NAME: &'static str = "PingService";   
}

#[tokio::main]
async fn main() {
   let mut addr: Address<Ping> = Registry::service().await;
}

Implementations

Returns an address of an actor that implements Service trait.

This function checks whether the corresponding actor is already running. If so, address of this actor is returned. Otherwise, actor is spawned first.

Panics

This method panics if two services having the same name will be attempted to be instantiated. All the names of services are expected to be unique.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.