Struct actix::registry::Registry

source ·
pub struct Registry { /* private fields */ }
Expand description

Actors registry

An Actor can register itself as a service. A Service can be defined as an ArbiterService, which is unique per arbiter, or a SystemService, which is unique per system.

If an arbiter service is used outside of a running arbiter, it panics.

§Examples

use actix::prelude::*;

#[derive(Message)]
#[rtype(result = "()")]
struct Ping;

#[derive(Default)]
struct MyActor1;

impl Actor for MyActor1 {
    type Context = Context<Self>;
}
impl actix::Supervised for MyActor1 {}

impl ArbiterService for MyActor1 {
   fn service_started(&mut self, ctx: &mut Context<Self>) {
      println!("Service started");
   }
}

impl Handler<Ping> for MyActor1 {
   type Result = ();

   fn handle(&mut self, _: Ping, ctx: &mut Context<Self>) {
      println!("ping");
   }
}

struct MyActor2;

impl Actor for MyActor2 {
   type Context = Context<Self>;

   fn started(&mut self, _: &mut Context<Self>) {
      // get MyActor1 address from the registry
      let act = MyActor1::from_registry();
      act.do_send(Ping);
   }
}

#[actix::main]
async fn main() {
    // Start MyActor2 in new Arbiter
    Arbiter::new().spawn_fn(|| {
        MyActor2.start();
    });
}

Implementations§

source§

impl Registry

source

pub fn get<A: ArbiterService + Actor<Context = Context<A>>>(&self) -> Addr<A>

👎Deprecated since 0.13.5: Renamed to get_or_start_default().

Queries registry for a type of actor (A), returning its address.

If actor is not registered, a new actor is started and its address is returned.

source

pub fn get_or_start_default<A: ArbiterService + Actor<Context = Context<A>>>( &self, ) -> Addr<A>

Queries registry for an actor, returning its address.

If actor of type A is not registered, a new actor is started and its address is returned.

source

pub fn try_get<A: Actor<Context = Context<A>>>(&self) -> Option<Addr<A>>

Queries registry for specific actor, returning its address.

Returns None if an actor of type A is not registered.

source

pub fn query<A: Actor<Context = Context<A>>>(&self) -> Option<Addr<A>>

Returns actor’s address if it is in the registry.

source

pub fn set<A: Actor<Context = Context<A>>>(addr: Addr<A>)

Adds an unregistered actor type to the registry by address.

§Panics

Panics if actor is already running

Trait Implementations§

source§

impl Clone for Registry

source§

fn clone(&self) -> Registry

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. 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> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.