January 2019
Intermediate to advanced
520 pages
14h 32m
English
Actor is a struct that implements the Actor trait. We'll use a struct with HashMap inside to count the number of incoming strings:
pub struct CountActor { counter: HashMap<String, Value>,}impl CountActor { pub fn new() -> Self { Self { counter: HashMap::new(), } }}
We added a new method to create an empty CountActor instance.
Now we can implement the Actor trait for our struct. The implementation is simple:
impl Actor for CountActor { type Context = Context<Self>;}
We specify a context and set it to the Context type. The actor trait contains the default implementation of different methods that help you to react on lifetime events of your actor:
Read now
Unlock full access