diff options
author | Liran Ringel <5730310+liranringel@users.noreply.github.com> | 2018-11-20 18:10:36 +0200 |
---|---|---|
committer | Toby Lawrence <tobz@users.noreply.github.com> | 2018-11-20 11:10:36 -0500 |
commit | 9b1a45cc6a15f5d2be17531dffc2f50d2b019646 (patch) | |
tree | da66c5c9574f2cd7ad11745e414fc34da2e35c6f /examples/chat-combinator.rs | |
parent | 477fa5580aa3796f97e3e0eb1325d4690b3b4e96 (diff) |
tests: handle errors properly in examples (#748)
Diffstat (limited to 'examples/chat-combinator.rs')
-rw-r--r-- | examples/chat-combinator.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/examples/chat-combinator.rs b/examples/chat-combinator.rs index 11754183..0572afbd 100644 --- a/examples/chat-combinator.rs +++ b/examples/chat-combinator.rs @@ -34,12 +34,12 @@ use std::env; use std::io::{BufReader}; use std::sync::{Arc, Mutex}; -fn main() { +fn main() -> Result<(), Box<std::error::Error>> { // Create the TCP listener we'll accept connections on. let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string()); - let addr = addr.parse().unwrap(); + let addr = addr.parse()?; - let socket = TcpListener::bind(&addr).unwrap(); + let socket = TcpListener::bind(&addr)?; println!("Listening on: {}", addr); // This is running on the Tokio runtime, so it will be multi-threaded. The @@ -49,10 +49,10 @@ fn main() { // 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)) + .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().unwrap(); + let addr = stream.peer_addr()?; println!("New Connection: {}", addr); @@ -143,8 +143,10 @@ fn main() { })); Ok(()) - }); + }) + .map_err(|err| println!("error occurred: {:?}", err)); // execute server tokio::run(srv); + Ok(()) } |