1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum SessionMessage {
Remove {
user: String,
},
}
impl SessionMessage {
pub fn from(json: String) -> Self {
serde_json::from_str(&json).expect("Unable to generate message from string")
}
pub fn to_json(&self) -> String {
serde_json::to_string(self).expect("Unable to generate JSON for session message")
}
}