diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-11 20:18:19 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-04-11 23:10:22 +1000 |
| commit | 5b109a175459e6428dafdd6aa5bedc6f598a3dff (patch) | |
| tree | 394de554cba4592a1ceb3bd8ed1b5f4091101625 /src/libstd/io/mod.rs | |
| parent | 0156af156d70efd5a3c96d0c5b8fc9bec39a7ae5 (diff) | |
| download | rust-5b109a175459e6428dafdd6aa5bedc6f598a3dff.tar.gz rust-5b109a175459e6428dafdd6aa5bedc6f598a3dff.zip | |
Add more type signatures to the docs; tweak a few of them.
Someone reading the docs won't know what the types of various things are, so this adds them in a few meaningful places to help with comprehension. cc #13423.
Diffstat (limited to 'src/libstd/io/mod.rs')
| -rw-r--r-- | src/libstd/io/mod.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index f384000896c..ccff857f606 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -97,8 +97,8 @@ Some examples of obvious things you might want to do ```rust # fn main() { } # fn foo() { - # #[allow(unused_must_use, dead_code)]; - use std::io::net::tcp::TcpListener; + # #![allow(dead_code)] + use std::io::{TcpListener, TcpStream}; use std::io::net::ip::{Ipv4Addr, SocketAddr}; use std::io::{Acceptor, Listener}; @@ -108,12 +108,19 @@ Some examples of obvious things you might want to do // bind the listener to the specified address let mut acceptor = listener.listen(); - // accept connections and process them - # fn handle_client<T>(_: T) {} + fn handle_client(mut stream: TcpStream) { + // ... + # &mut stream; // silence unused mutability/variable warning + } + // accept connections and process them, spawning a new tasks for each one for stream in acceptor.incoming() { - spawn(proc() { - handle_client(stream); - }); + match stream { + Err(e) => { /* connection failed */ } + Ok(stream) => spawn(proc() { + // connection succeeded + handle_client(stream) + }) + } } // close the socket server |
