Skip to content

Commit 7222ba9

Browse files
committed
auto merge of #18818 : steveklabnik/rust/tcp_doc, r=alexcrichton
This suggests that you must call it, which is normally not what you want to do. See here: http://www.reddit.com/r/rust/comments/2lpw9k/rust_irc_example_looking_for_feedback/clxnxxc?context=4
2 parents 54c628c + 534fd3a commit 7222ba9

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/libstd/io/net/tcp.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ use sys::tcp::TcpAcceptor as TcpAcceptorImp;
3434
/// A structure which represents a TCP stream between a local socket and a
3535
/// remote socket.
3636
///
37+
/// The socket will be closed when the value is dropped.
38+
///
3739
/// # Example
3840
///
3941
/// ```no_run
40-
/// # #![allow(unused_must_use)]
4142
/// use std::io::TcpStream;
4243
///
43-
/// let mut stream = TcpStream::connect("127.0.0.1:34254");
44+
/// {
45+
/// let mut stream = TcpStream::connect("127.0.0.1:34254");
46+
///
47+
/// // ignore the Result
48+
/// let _ = stream.write(&[1]);
4449
///
45-
/// stream.write(&[1]);
46-
/// let mut buf = [0];
47-
/// stream.read(&mut buf);
48-
/// drop(stream); // close the connection
50+
/// let mut buf = [0];
51+
/// let _ = stream.read(&mut buf); // ignore here too
52+
/// } // the stream is closed here
4953
/// ```
5054
pub struct TcpStream {
5155
inner: TcpStreamImp,

0 commit comments

Comments
 (0)