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 1 commit
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
Prev Previous commit
Next Next commit
Improve documentation for std::io::LineWriter
Beef up the struct docs, add examples for the methods.
  • Loading branch information
steveklabnik committed Jul 21, 2015
commit 94b8f2820f3de88f53a64a635d135f2c1c47b117
124 changes: 121 additions & 3 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,74 @@ impl<W> fmt::Display for IntoInnerError<W> {
}
}

/// Wraps a Writer and buffers output to it, flushing whenever a newline
/// Wraps a writer and buffers output to it, flushing whenever a newline
/// (`0x0a`, `'\n'`) is detected.
///
/// The buffer will be written out when the writer is dropped.
/// The [`BufWriter`][bufwriter] struct wraps a writer and buffers its output.
/// But it only does this batched write when it goes out of scope, or when the
/// internal buffer is full. Sometimes, you'd prefer to write each line as it's
/// completed, rather than the entire buffer at once. Enter `LineWriter`. It
/// does exactly that.
///
/// [bufwriter]: struct.BufWriter.html
///
/// If there's still a partial line in the buffer when the `LineWriter` is
/// dropped, it will flush those contents.
///
/// # Examples
///
/// We can use `LineWriter` to write one line at a time, significantly
/// reducing the number of actual writes to the file.
///
/// ```
/// use std::fs::File;
/// use std::io::prelude::*;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let road_not_taken = b"I shall be telling this with a sigh
/// Somewhere ages and ages hence:
/// Two roads diverged in a wood, and I -
/// I took the one less traveled by,
/// And that has made all the difference.";
///
/// let file = try!(File::create("poem.txt"));
/// let mut file = LineWriter::new(file);
///
/// for &byte in road_not_taken.iter() {
/// file.write(&[byte]).unwrap();
/// }
///
/// // let's check we did the right thing.
/// let mut file = try!(File::open("poem.txt"));
/// let mut contents = String::new();
///
/// try!(file.read_to_string(&mut contents));
///
/// assert_eq!(contents.as_bytes(), &road_not_taken[..]);
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub struct LineWriter<W: Write> {
inner: BufWriter<W>,
}

impl<W: Write> LineWriter<W> {
/// Creates a new `LineWriter`
/// Creates a new `LineWriter`.
///
/// # Examples
///
/// ```
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = try!(File::create("poem.txt"));
/// let file = LineWriter::new(file);
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new(inner: W) -> LineWriter<W> {
// Lines typically aren't that long, don't use a giant buffer
Expand All @@ -436,25 +493,86 @@ impl<W: Write> LineWriter<W> {

/// Creates a new `LineWriter` with a specified capacity for the internal
/// buffer.
///
/// # Examples
///
/// ```
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = try!(File::create("poem.txt"));
/// let file = LineWriter::with_capacity(100, file);
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(cap: usize, inner: W) -> LineWriter<W> {
LineWriter { inner: BufWriter::with_capacity(cap, inner) }
}

/// Gets a reference to the underlying writer.
///
/// # Examples
///
/// ```
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = try!(File::create("poem.txt"));
/// let file = LineWriter::new(file);
///
/// let reference = file.get_ref();
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_ref(&self) -> &W { self.inner.get_ref() }

/// Gets a mutable reference to the underlying writer.
///
/// Caution must be taken when calling methods on the mutable reference
/// returned as extra writes could corrupt the output stream.
///
/// # Examples
///
/// ```
/// use std::fs::File;
/// use std::io::prelude::*;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = try!(File::create("poem.txt"));
/// let mut file = LineWriter::new(file);
///
/// // we can use reference just like file
/// let reference = file.get_mut();
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_mut(&mut self) -> &mut W { self.inner.get_mut() }

/// Unwraps this `LineWriter`, returning the underlying writer.
///
/// The internal buffer is written out before returning the writer.
///
/// # Examples
///
/// ```
/// use std::fs::File;
/// use std::io::LineWriter;
///
/// # fn foo() -> std::io::Result<()> {
/// let file = try!(File::create("poem.txt"));
///
/// let writer: LineWriter<File> = LineWriter::new(file);
///
/// let file: File = try!(writer.into_inner());
/// # Ok(())
/// # }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn into_inner(self) -> Result<W, IntoInnerError<LineWriter<W>>> {
self.inner.into_inner().map_err(|IntoInnerError(buf, e)| {
Expand Down