Fix serialization.

This commit is contained in:
Paul Makles
2020-04-13 16:29:48 +01:00
parent 577f25642e
commit 0f793f84a2
7 changed files with 83 additions and 31 deletions

View File

@@ -1,8 +1,27 @@
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
pub mod message;
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum Notification {
MessageCreate(message::Create),
}
impl Notification {
pub fn serialize(self) -> String {
if let Value::Object(obj) = json!(self) {
let (key, value) = obj.iter().next().unwrap();
if let Value::Object(data) = value {
let mut data = data.clone();
data.insert("type".to_string(), Value::String(key.to_string()));
json!(data).to_string()
} else {
unreachable!()
}
} else {
unreachable!()
}
}
}