diff options
author | oberien <jaro.fietz@gmx.de> | 2016-10-11 20:08:13 +0200 |
---|---|---|
committer | oberien <jaro.fietz@gmx.de> | 2016-10-11 20:08:13 +0200 |
commit | 315f6018229f38b34107096924e6f09a52527cac (patch) | |
tree | 0114925f0602ca0d71b9d86975537e845d11ca8b /examples/chat.rs | |
parent | b227738bd7e5347ece625e256cb2e9a90aa3cae2 (diff) |
ref(examples): Minor refactoring in chat example
* Move connections-clone down a bit
* Use `Ok` and `Err` as IntoFuture
Diffstat (limited to 'examples/chat.rs')
-rw-r--r-- | examples/chat.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/chat.rs b/examples/chat.rs index 91f8c47b..18a09d8a 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -49,7 +49,6 @@ fn main() { let iter = stream::iter::<_, _, std::io::Error>(iter::repeat(()).map(Ok)); // Then we fold it as infinite loop let socket_reader = iter.fold(reader, move |reader, _| { - let connections = connections_inner.clone(); // read line let amt = io::read_until(reader, '\n' as u8, vec![]); // check if we hit EOF and need to close the connection @@ -57,13 +56,14 @@ fn main() { // EOF was hit without reading a delimiter if vec.len() == 0 { let err = Error::new(ErrorKind::BrokenPipe, "Broken Pipe"); - futures::failed(err).boxed() + Err(err) } else { - futures::finished((reader, vec)).boxed() + Ok((reader, vec)) } }); // convert bytes into string let amt = amt.map(|(reader, vec)| (reader, String::from_utf8(vec))); + let connections = connections_inner.clone(); amt.map(move |(reader, message)| { println!("{}: {:?}", addr, message); let conns = connections.borrow_mut(); |