pub trait SystemService: Actor<Context = Context<Self>> + Supervised + Default {
    // Provided methods
    fn start_service(wrk: &ArbiterHandle) -> Addr<Self> { ... }
    fn service_started(&mut self, ctx: &mut Context<Self>) { ... }
    fn from_registry() -> Addr<Self> { ... }
}
Expand description

Trait defines system’s service.

Provided Methods§

source

fn start_service(wrk: &ArbiterHandle) -> Addr<Self>

Construct and start system service

source

fn service_started(&mut self, ctx: &mut Context<Self>)

Method is called during service initialization.

source

fn from_registry() -> Addr<Self>

Get actor’s address from system registry

Examples found in repository?
examples/mock.rs (line 22)
21
22
23
24
25
    fn handle(&mut self, _msg: Question, _ctx: &mut Context<Self>) -> Self::Result {
        let act_addr = AnswerActor::from_registry();
        let request = act_addr.send(Question {});
        Box::pin(async move { request.await.unwrap() })
    }
More examples
Hide additional examples
examples/weak_addr.rs (line 88)
86
87
88
89
90
91
92
93
    fn started(&mut self, ctx: &mut Self::Context) {
        println!("🐰 starting Client");
        TimeService::from_registry()
            .send(RegisterForTime(ctx.address().downgrade()))
            .into_actor(self)
            .then(|_, _slf, _| fut::ready(()))
            .spawn(ctx);
    }
examples/weak_recipient.rs (line 88)
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    fn started(&mut self, ctx: &mut Self::Context) {
        println!("🐰 starting ClientA");
        TimeService::from_registry()
            .send(RegisterForTime(ctx.address().downgrade().recipient()))
            .into_actor(self)
            .then(|_, _slf, _| fut::ready(()))
            .spawn(ctx);
    }

    fn stopping(&mut self, _ctx: &mut Self::Context) -> Running {
        println!("🐰 stopping ClientA");
        Running::Stop
    }

    fn stopped(&mut self, _ctx: &mut Self::Context) {
        println!("🐰 stopped ClientA");
    }
}

impl Handler<TimePing> for ClientA {
    type Result = ();

    fn handle(&mut self, msg: TimePing, _ctx: &mut Self::Context) -> Self::Result {
        println!("🐰 ClientA received ping: {:?}", msg.0);
    }
}

#[derive(Debug, Default)]
pub struct ClientB;

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

    fn started(&mut self, ctx: &mut Self::Context) {
        println!("🐇 starting ClientB");
        TimeService::from_registry()
            .send(RegisterForTime(ctx.address().downgrade().recipient()))
            .into_actor(self)
            .then(|_, _slf, _| fut::ready(()))
            .spawn(ctx);
    }

Object Safety§

This trait is not object safe.

Implementors§