Building our state actor
When it comes to our state actor, we must send and receive messages. Our state actor will also have a state where the actor will store the chat logs to be referenced. With the state actor mechanisms in mind, it will not be surprising that we have the following imports in the src/actors/state.rs
file:
use std::collections::{HashMap, VecDeque}; use std::mem; use tokio::sync::mpsc::{Sender, Receiver}; use super::messages::{MessageType, StateActorMessage};
The only difference in the imports is the mem
module. The mem
module will enable us to allocate memory. We will cover how we use the mem
module when we get the message from the state of the actor. We can also see that we have imported HashMap
and VecDeque
to handle the state of the actor.
Now that we have imported what we need, we can define our actor struct with the following code:
#[derive(Debug)] pub struct StateActor { pub chat_queue: VecDeque<i32>, &...