mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 22:49:18 +00:00
simplify json serialization code
This commit is contained in:
parent
cde4a8a977
commit
05ee5a8b60
|
@ -295,18 +295,21 @@ impl Handler<StandardMessage> for ChatServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
struct WebsocketResponse<T> {
|
||||||
|
op: String,
|
||||||
|
data: T,
|
||||||
|
}
|
||||||
|
|
||||||
fn to_json_string<T>(op: &UserOperation, data: T) -> Result<String, Error>
|
fn to_json_string<T>(op: &UserOperation, data: T) -> Result<String, Error>
|
||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let mut json = serde_json::to_value(&data)?;
|
let response = WebsocketResponse {
|
||||||
match json.as_object_mut() {
|
op: op.to_string(),
|
||||||
Some(j) => j.insert("op".to_string(), serde_json::to_value(op.to_string())?),
|
data,
|
||||||
None => return Err(format_err!("")),
|
|
||||||
};
|
};
|
||||||
// TODO: it seems like this is never called?
|
Ok(serde_json::to_string(&response)?)
|
||||||
let x = serde_json::to_string(&json)?;
|
|
||||||
Ok(x)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_json_message(chat: &mut ChatServer, msg: StandardMessage) -> Result<String, Error> {
|
fn parse_json_message(chat: &mut ChatServer, msg: StandardMessage) -> Result<String, Error> {
|
||||||
|
|
Loading…
Reference in a new issue