Struct Registry

Source
pub struct Registry { /* private fields */ }
Available 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§

Source§

impl Registry

Source

pub async fn service<S: Service + Sized + 'static>() -> Address<S>

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§

Source§

impl Debug for Registry

Source§

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

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

impl Default for Registry

Source§

fn default() -> Registry

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

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.