I'm making a small fighting game with Actix Web and Actix WebSocket. My client sends a JSON that contains attack data, and I'm wondering how to serialize the JSON into the corresponding Rust struct. It seems that StreamHandler does not allow to handle anything other than text.
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWs {
fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
match msg {
Ok(ws::Message::Ping(msg)) => ctx.pong(&msg),
Ok(ws::Message::Text(text)) => ctx.text(text),
Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
_ => (),
}
}
}