diff options
Diffstat (limited to 'examples/chat-combinator.rs')
-rw-r--r-- | examples/chat-combinator.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/examples/chat-combinator.rs b/examples/chat-combinator.rs index 0572afbd..b81e8f7c 100644 --- a/examples/chat-combinator.rs +++ b/examples/chat-combinator.rs @@ -21,17 +21,17 @@ #![deny(warnings)] -extern crate tokio; extern crate futures; +extern crate tokio; use tokio::io; use tokio::net::TcpListener; use tokio::prelude::*; use std::collections::HashMap; -use std::iter; use std::env; -use std::io::{BufReader}; +use std::io::BufReader; +use std::iter; use std::sync::{Arc, Mutex}; fn main() -> Result<(), Box<std::error::Error>> { @@ -48,8 +48,12 @@ fn main() -> Result<(), Box<std::error::Error>> { // The server task asynchronously iterates over and processes each incoming // connection. - let srv = socket.incoming() - .map_err(|e| {println!("failed to accept socket; error = {:?}", e); e}) + let srv = socket + .incoming() + .map_err(|e| { + println!("failed to accept socket; error = {:?}", e); + e + }) .for_each(move |stream| { // The client's socket address let addr = stream.peer_addr()?; @@ -91,9 +95,7 @@ fn main() -> Result<(), Box<std::error::Error>> { // Convert the bytes we read into a string, and then send that // string to all other connected clients. - let line = line.map(|(reader, vec)| { - (reader, String::from_utf8(vec)) - }); + let line = line.map(|(reader, vec)| (reader, String::from_utf8(vec))); // Move the connection state into the closure below. let connections = connections_inner.clone(); @@ -105,15 +107,17 @@ fn main() -> Result<(), Box<std::error::Error>> { if let Ok(msg) = message { // For each open connection except the sender, send the // string via the channel. - let iter = conns.iter_mut() - .filter(|&(&k, _)| k != addr) - .map(|(_, v)| v); + let iter = conns + .iter_mut() + .filter(|&(&k, _)| k != addr) + .map(|(_, v)| v); for tx in iter { tx.unbounded_send(format!("{}: {}", addr, msg)).unwrap(); } } else { let tx = conns.get_mut(&addr).unwrap(); - tx.unbounded_send("You didn't send valid UTF-8.".to_string()).unwrap(); + tx.unbounded_send("You didn't send valid UTF-8.".to_string()) + .unwrap(); } reader |