Skip to content

Rollup of 18 pull requests #27199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 47 commits into from
Closed
Changes from 2 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
fc16c3e
Improve the expected constant integer error message
jawline Jul 4, 2015
3a009cb
Merge branch 'master' of https://github.com/mmjack/rust
jawline Jul 4, 2015
f395b2b
Make the message slightly clearer
jawline Jul 4, 2015
8c5ffd3
Reduce line length
jawline Jul 4, 2015
02dd732
Self.sess -> txc.sess
jawline Jul 5, 2015
4872463
Remove 'valid' from error
jawline Jul 5, 2015
affbc72
Modified to add 'found' to error message instead
jawline Jul 19, 2015
b684826
add test for #20162
apasel422 Jul 19, 2015
871ccfb
Add a test for #26468
dotdash Jul 20, 2015
9bb6545
add test for #14229
apasel422 Jul 20, 2015
4c73dbd
add test for #19404
apasel422 Jul 20, 2015
31a62d3
s/has gained/has not gained/g
pfalabella Jul 20, 2015
a7e5c63
add test for #10436
apasel422 Jul 20, 2015
3ae7b72
Fix wording nit for E0253
AlisdairO Jul 20, 2015
27fc0f2
Document iterators in std::io
steveklabnik Jul 20, 2015
686d326
Add diagnostics for E0172, fix inline error message for E0139
AlisdairO Jul 19, 2015
7e7ec6b
Document structures in std::io::utils
steveklabnik Jul 20, 2015
9e18326
Update docs for take and broadcast
steveklabnik Jul 20, 2015
a29c834
Add travis config to TRPL: release channels
steveklabnik Jul 21, 2015
eb39df0
Improve documentation for std::io::BufWriter
steveklabnik Jul 20, 2015
0eb7303
Add E0403 error explanation
GuillaumeGomez Jul 17, 2015
cd385cb
Add E0405 error explanation
GuillaumeGomez Jul 17, 2015
bc79f20
Add E0404 error explanation
GuillaumeGomez Jul 17, 2015
9581154
Add E0407 error explanation
GuillaumeGomez Jul 17, 2015
c13295b
Add E0428 error explanation
GuillaumeGomez Jul 17, 2015
d2aee95
Expand documentation for IntoInnerError
steveklabnik Jul 20, 2015
94b8f28
Improve documentation for std::io::LineWriter
steveklabnik Jul 20, 2015
2e919b4
Add E0433 error explanation
GuillaumeGomez Jul 17, 2015
e6d8434
add test for #14382
apasel422 Jul 20, 2015
e7b6e01
Rollup merge of #26778 - jawline:master, r=pnkfelix
steveklabnik Jul 21, 2015
f114aec
Rollup merge of #27084 - GuillaumeGomez:patch-2, r=brson
steveklabnik Jul 21, 2015
1a6655b
Rollup merge of #27127 - AlisdairO:diagnostics172, r=Manishearth
steveklabnik Jul 21, 2015
836887b
Rollup merge of #27131 - apasel422:issue-20162, r=arielb1
steveklabnik Jul 21, 2015
a0cea5f
Rollup merge of #27140 - dotdash:test-26468, r=luqmana
steveklabnik Jul 21, 2015
2046232
Rollup merge of #27146 - apasel422:issue-14229, r=alexcrichton
steveklabnik Jul 21, 2015
ef60ea7
Rollup merge of #27147 - apasel422:issue-19404, r=alexcrichton
steveklabnik Jul 21, 2015
d89ca75
Rollup merge of #27151 - pfalabella:patch-2, r=steveklabnik
steveklabnik Jul 21, 2015
fcfce41
Rollup merge of #27154 - apasel422:issue-10436, r=Gankro
steveklabnik Jul 21, 2015
9f9e2dd
Rollup merge of #27155 - steveklabnik:doc_std_io_buf_writer, r=alexcr…
steveklabnik Jul 21, 2015
0715fe7
Rollup merge of #27156 - AlisdairO:diagnostics253, r=Manishearth
steveklabnik Jul 21, 2015
30a54aa
Rollup merge of #27157 - steveklabnik:doc_std_io_iterators, r=alexcri…
steveklabnik Jul 21, 2015
f0fc106
Rollup merge of #27158 - apasel422:issue-14382, r=alexcrichton
steveklabnik Jul 21, 2015
74c6d04
Rollup merge of #27164 - steveklabnik:doc_io_utils, r=alexcrichton
steveklabnik Jul 21, 2015
ce5406e
Rollup merge of #27166 - steveklabnik:doc_std_io_linewriter, r=alexcr…
steveklabnik Jul 21, 2015
192523c
Rollup merge of #27167 - steveklabnik:doc_std_io_take, r=alexcrichton
steveklabnik Jul 21, 2015
5e3cfa3
Rollup merge of #27170 - steveklabnik:doc_std_io_intoinnererror, r=al…
steveklabnik Jul 21, 2015
2b1472e
Rollup merge of #27175 - steveklabnik:channels_plus_travis, r=alexcri…
steveklabnik Jul 21, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 98 additions & 5 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,49 @@ impl<R: Seek> Seek for BufReader<R> {
}
}

/// Wraps a Writer and buffers output to it.
/// Wraps a writer and buffers its output.
///
/// It can be excessively inefficient to work directly with a `Write`. For
/// example, every call to `write` on `TcpStream` results in a system call. A
/// `BufWriter` keeps an in memory buffer of data and writes it to the
/// underlying `Write` in large, infrequent batches.
/// It can be excessively inefficient to work directly with something that
/// implements `Write`. For example, every call to `write` on `TcpStream`
/// results in a system call. A `BufWriter` keeps an in-memory buffer of data
/// and writes it to an underlying writer in large, infrequent batches.
///
/// The buffer will be written out when the writer is dropped.
///
/// # Examples
///
/// Let's write the numbers one through ten to a `TcpStream`:
///
/// ```no_run
/// use std::io::prelude::*;
/// use std::net::TcpStream;
///
/// let mut stream = TcpStream::connect("127.0.0.1:34254").unwrap();
///
/// for i in 1..10 {
/// stream.write(&[i]).unwrap();
/// }
/// ```
///
/// Because we're not buffering, we write each one in turn, incurring the
/// overhead of a system call per byte written. We can fix this with a
/// `BufWriter`:
///
/// ```no_run
/// use std::io::prelude::*;
/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let mut stream = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
///
/// for i in 1..10 {
/// stream.write(&[i]).unwrap();
/// }
/// ```
///
/// By wrapping the stream with a `BufWriter`, these ten writes are all grouped
/// together by the buffer, and will all be written out in one system call when
/// the `stream` is dropped.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BufWriter<W: Write> {
inner: Option<W>,
Expand All @@ -275,12 +310,33 @@ pub struct IntoInnerError<W>(W, Error);

impl<W: Write> BufWriter<W> {
/// Creates a new `BufWriter` with a default buffer capacity.
///
/// # Examples
///
/// ```no_run
/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(inner: W) -> BufWriter<W> {
BufWriter::with_capacity(DEFAULT_BUF_SIZE, inner)
}

/// Creates a new `BufWriter` with the specified buffer capacity.
///
/// # Examples
///
/// Creating a buffer with a buffer of a hundred bytes.
///
/// ```no_run
/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let stream = TcpStream::connect("127.0.0.1:34254").unwrap();
/// let mut buffer = BufWriter::with_capacity(100, stream);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(cap: usize, inner: W) -> BufWriter<W> {
BufWriter {
Expand Down Expand Up @@ -313,6 +369,18 @@ impl<W: Write> BufWriter<W> {
}

/// Gets a reference to the underlying writer.
///
/// # Examples
///
/// ```no_run
/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
///
/// // we can use reference just like buffer
/// let reference = buffer.get_ref();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_ref(&self) -> &W { self.inner.as_ref().unwrap() }

Expand All @@ -321,12 +389,37 @@ impl<W: Write> BufWriter<W> {
/// # Warning
///
/// It is inadvisable to directly write to the underlying writer.
///
/// # Examples
///
/// ```no_run
/// use std::io::prelude::*;
/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
///
/// // we can use reference just like buffer
/// let reference = buffer.get_mut();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self) -> &mut W { self.inner.as_mut().unwrap() }

/// Unwraps this `BufWriter`, returning the underlying writer.
///
/// The buffer is written out before returning the writer.
///
/// # Examples
///
/// ```no_run
/// use std::io::BufWriter;
/// use std::net::TcpStream;
///
/// let mut buffer = BufWriter::new(TcpStream::connect("127.0.0.1:34254").unwrap());
///
/// // unwrap the TcpStream and flush the buffer
/// let stream = buffer.into_inner().unwrap();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> {
match self.flush_buf() {
Expand Down