Skip to content

Commit

Permalink
Rollup merge of rust-lang#59498 - mbrubeck:write_all, r=Centril
Browse files Browse the repository at this point in the history
Use 'write_all' instead of 'write' in example code

Using `write` without looping and checking the result can cause silent data loss.  Example code should use `write_all` so that people don't copy this pattern.  (Of course this does not include example code for docs that are specifically about the `write` method.)
  • Loading branch information
Centril authored Mar 29, 2019
2 parents bf3e6c6 + 8dbae79 commit 0494cff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ pub trait Write {
/// fn main() -> std::io::Result<()> {
/// let mut buffer = BufWriter::new(File::create("foo.txt")?);
///
/// buffer.write(b"some bytes")?;
/// buffer.write_all(b"some bytes")?;
/// buffer.flush()?;
/// Ok(())
/// }
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ pub struct StdoutLock<'a> {
/// use std::io::{self, Write};
///
/// fn main() -> io::Result<()> {
/// io::stdout().write(b"hello world")?;
/// io::stdout().write_all(b"hello world")?;
///
/// Ok(())
/// }
Expand All @@ -420,7 +420,7 @@ pub struct StdoutLock<'a> {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
///
/// handle.write(b"hello world")?;
/// handle.write_all(b"hello world")?;
///
/// Ok(())
/// }
Expand Down Expand Up @@ -460,7 +460,7 @@ impl Stdout {
/// let stdout = io::stdout();
/// let mut handle = stdout.lock();
///
/// handle.write(b"hello world")?;
/// handle.write_all(b"hello world")?;
///
/// Ok(())
/// }
Expand Down Expand Up @@ -558,7 +558,7 @@ pub struct StderrLock<'a> {
/// use std::io::{self, Write};
///
/// fn main() -> io::Result<()> {
/// io::stderr().write(b"hello world")?;
/// io::stderr().write_all(b"hello world")?;
///
/// Ok(())
/// }
Expand All @@ -573,7 +573,7 @@ pub struct StderrLock<'a> {
/// let stderr = io::stderr();
/// let mut handle = stderr.lock();
///
/// handle.write(b"hello world")?;
/// handle.write_all(b"hello world")?;
///
/// Ok(())
/// }
Expand Down Expand Up @@ -613,7 +613,7 @@ impl Stderr {
/// let stderr = io::stderr();
/// let mut handle = stderr.lock();
///
/// handle.write(b"hello world")?;
/// handle.write_all(b"hello world")?;
///
/// Ok(())
/// }
Expand Down

0 comments on commit 0494cff

Please sign in to comment.