From ec03b72c7eade62153e4d3478f09d4b6208955fb Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Sat, 16 Mar 2019 12:05:15 +0000 Subject: [PATCH] Rename newstate to stateupdate --- src/main.rs | 4 ++-- src/web.rs | 2 +- src/web/websocket.rs | 22 +++++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1186276..ef891e4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -68,8 +68,8 @@ impl Server { }, recv(rx) -> state => { let thestate = state.unwrap(); - tx.send(thestate).unwrap(); - ws_tx_wait.send(web::websocket::NewState::from(thestate)).expect("Error sending to websocket channel"); + tx.send(thestate).unwrap(); // Send update to driver + ws_tx_wait.send(web::websocket::StateUpdate::from(thestate)).expect("Error sending to websocket channel"); // And to web interface } } } diff --git a/src/web.rs b/src/web.rs index 3b01d32..446e0c1 100644 --- a/src/web.rs +++ b/src/web.rs @@ -17,7 +17,7 @@ const INDEX: &'static [u8] = include_bytes!("static/index.html"); impl WebServer { pub fn run( addr: std::net::SocketAddr, - ) -> (WebServer, futures::sync::mpsc::Sender) { + ) -> (WebServer, futures::sync::mpsc::Sender) { let (ws_tx_tx, ws_tx_rx) = mpsc::channel(); // Channel the websocket sender will be sent on let (shutdown_tx, shutdown_rx) = mpsc::channel(); let (tx, rx) = mpsc::channel(); diff --git a/src/web/websocket.rs b/src/web/websocket.rs index 31e7689..552c196 100644 --- a/src/web/websocket.rs +++ b/src/web/websocket.rs @@ -17,25 +17,25 @@ pub struct Disconnect { } #[derive(Message)] -pub struct NewState(Result); +pub struct StateUpdate(Result); -// Basically just convenience so you don't have to construct a NewState with an Ok all the time -impl From for NewState { +// Basically just convenience so you don't have to construct a StateUpdate with an Ok all the time +impl From for StateUpdate { fn from(state: TallyState) -> Self { - NewState(Ok(state)) + StateUpdate(Ok(state)) } } pub struct WSServer { - state_tx_tx: std::sync::mpsc::Sender>, + state_tx_tx: std::sync::mpsc::Sender>, clients: HashMap, ()>, } -// This lets the WSServer act as a futures channel reciever, with incoming NewStates being handled like actix messages -impl StreamHandler for WSServer { - fn handle(&mut self, item: NewState, _: &mut Context) { +// This lets the WSServer act as a futures channel reciever, with incoming StateUpdates being handled like actix messages +impl StreamHandler for WSServer { + fn handle(&mut self, item: StateUpdate, _: &mut Context) { if let Ok(state) = item.0 { - self.broadcast(serde_json::to_string(&state).unwrap()) + self.broadcast(serde_json::to_string(&state).unwrap()); } } } @@ -45,14 +45,14 @@ impl Actor for WSServer { fn started(&mut self, ctx: &mut Self::Context) { log::info!("Websocket started"); - let (tx, rx) = futures::sync::mpsc::channel::(10); + let (tx, rx) = futures::sync::mpsc::channel::(10); Self::add_stream(rx, ctx); self.state_tx_tx.send(tx).unwrap(); } } impl WSServer { - pub fn new(state_tx_tx: std::sync::mpsc::Sender>) -> WSServer { + pub fn new(state_tx_tx: std::sync::mpsc::Sender>) -> WSServer { WSServer { state_tx_tx, clients: HashMap::new(),