mirror of https://github.com/LemmyNet/lemmy.git
simplify json serialization code
parent
047ec97e18
commit
baf77bb6be
|
@ -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 New Issue