summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-04-11 12:01:44 -0700
committerbors <bors@rust-lang.org>2014-04-11 12:01:44 -0700
commitb7e93067732ac1398a74958a3b1b0f6fa72fee8d (patch)
treead241d3f0bba0636e14e6c1c6f8c465c902674bd /src/libstd/io
parent8b6091e8f1f5531fe907f84b6a2b27af04a95e8f (diff)
parent5b109a175459e6428dafdd6aa5bedc6f598a3dff (diff)
downloadrust-b7e93067732ac1398a74958a3b1b0f6fa72fee8d.tar.gz
rust-b7e93067732ac1398a74958a3b1b0f6fa72fee8d.zip
auto merge of #13458 : huonw/rust/doc-signatures, r=alexcrichton
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')
-rw-r--r--src/libstd/io/mod.rs21
-rw-r--r--src/libstd/io/net/tcp.rs24
2 files changed, 29 insertions, 16 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
diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs
index 02c061c54dd..2253b22796f 100644
--- a/src/libstd/io/net/tcp.rs
+++ b/src/libstd/io/net/tcp.rs
@@ -100,10 +100,10 @@ impl Writer for TcpStream {
 /// # Example
 ///
 /// ```rust
-/// # fn main() {}
+/// # 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};
 ///
@@ -113,12 +113,19 @@ impl Writer for TcpStream {
 /// // 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
@@ -728,4 +735,3 @@ mod test {
         assert_eq!(s.read_to_end(), Ok(vec!(1)));
     })
 }
-