hide some generics that don't need to be generic
This commit is contained in:
parent
03e4512839
commit
eb7ea021b0
3 changed files with 8 additions and 7 deletions
|
@ -5,7 +5,7 @@ use anyhow::{Context, Error, Result};
|
|||
use future::ok;
|
||||
use futures::prelude::*;
|
||||
use net::{ClientMessage, ServerMessage, server::greet};
|
||||
use serde_json::{from_str, to_string, Value};
|
||||
use serde_json::{from_str, to_string};
|
||||
use std::net::ToSocketAddrs;
|
||||
use stream::FuturesUnordered;
|
||||
use structopt::StructOpt;
|
||||
|
@ -53,7 +53,7 @@ async fn main() -> Result<()> {
|
|||
async fn handle_socket(websocket: WebSocket) -> Result<()> {
|
||||
let (sink, mut source) = websocket.split();
|
||||
|
||||
let mut sink = sink.with(|msg: ServerMessage<Vec<Value>, Value>| {
|
||||
let mut sink = sink.with(|msg: ServerMessage| {
|
||||
let json = to_string(&msg).expect("JSON encoding shouldn't fail");
|
||||
ok::<Message, Error>(Message::text(json))
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ async fn handle_socket(websocket: WebSocket) -> Result<()> {
|
|||
match source.next().await {
|
||||
Some(Ok(msg)) => match msg.to_str() {
|
||||
Ok(json) => {
|
||||
let msg = from_str::<ClientMessage<Value, Value>>(json).context("Parsing JSON")?;
|
||||
let msg = from_str::<ClientMessage>(json).context("Parsing JSON")?;
|
||||
debug!("Client message: {:?}", &msg);
|
||||
}
|
||||
Err(()) => debug!("Non-text message"),
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
pub mod server;
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[serde(tag = "t")]
|
||||
pub enum ClientMessage<I, S> {
|
||||
pub enum ClientMessage<I = Value, S = Value> {
|
||||
#[serde(rename = "s")]
|
||||
SetState { s: S },
|
||||
#[serde(rename = "i")]
|
||||
|
@ -21,7 +22,7 @@ pub struct Meta {
|
|||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[serde(tag = "t")]
|
||||
pub enum ServerMessage<I, S> {
|
||||
pub enum ServerMessage<I = Vec<Value>, S = Value> {
|
||||
#[serde(rename = "m")]
|
||||
Meta {
|
||||
#[serde(flatten)]
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use anyhow::{Context, Error, Result};
|
||||
use super::*;
|
||||
use futures::prelude::*;
|
||||
use serde_json::{Value, json};
|
||||
use serde_json::json;
|
||||
use stream::iter;
|
||||
|
||||
pub async fn greet<T>(sink: &mut T) -> Result<()>
|
||||
where T: Sink<ServerMessage<Vec<Value>, Value>, Error = Error> + Unpin
|
||||
where T: Sink<ServerMessage, Error = Error> + Unpin
|
||||
{
|
||||
let mut greeting = iter(vec![
|
||||
ServerMessage::Meta {
|
||||
|
|
Loading…
Reference in a new issue