messaging_thread_pool/samples/
chat_room.rs1use messaging_thread_pool_macros::pool_item;
2
3use crate as messaging_thread_pool;
5
6#[derive(Debug)]
12pub struct ChatRoom {
13 #[allow(dead_code)]
14 id: u64,
15 pub history: Vec<String>,
16}
17
18impl ChatRoom {
19 pub fn new(id: u64) -> Self {
21 Self {
22 id,
23 history: Vec::new(),
24 }
25 }
26}
27
28#[pool_item]
29impl ChatRoom {
30 #[messaging(PostRequest, PostResponse)]
33 pub fn post(&mut self, user: String, text: String) -> usize {
34 let entry = format!("{}: {}", user, text);
35 self.history.push(entry);
36 self.history.len() - 1
37 }
38
39 #[messaging(GetHistoryRequest, GetHistoryResponse)]
41 pub fn get_history(&self) -> Vec<String> {
42 self.history.clone()
43 }
44}