zero4rs/websocket/webchat/input/
actions.rs1use actix::Message as ActixMessage;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5use bytestring::ByteString;
6
7#[derive(Serialize, Deserialize)]
8pub enum Action {
9 Subscribe,
12 Unsubscribe,
13
14 SendMessage, }
17
18#[derive(Serialize, Deserialize, ActixMessage)]
19#[rtype(result = "()")]
20pub struct Input {
21 pub id: Option<String>,
22 pub action: Action,
23 pub data: Value,
24}
25
26impl From<Input> for ByteString {
27 fn from(val: Input) -> Self {
28 let json_string = serde_json::to_string(&val).unwrap();
29 let byte_string: ByteString = ByteString::from(json_string);
30
31 byte_string
32 }
33}