Skip to content

In doc examples, don't ignore read/write results #59532

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

Merged
merged 1 commit into from
Mar 30, 2019
Merged
Changes from all commits
Commits
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
25 changes: 19 additions & 6 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
//! let mut buffer = [0; 10];
//!
//! // read up to 10 bytes
//! f.read(&mut buffer)?;
//! let n = f.read(&mut buffer)?;
//!
//! println!("The bytes: {:?}", buffer);
//! println!("The bytes: {:?}", &buffer[..n]);
//! Ok(())
//! }
//! ```
Expand Down Expand Up @@ -56,9 +56,9 @@
//! f.seek(SeekFrom::End(-10))?;
//!
//! // read up to 10 bytes
//! f.read(&mut buffer)?;
//! let n = f.read(&mut buffer)?;
//!
//! println!("The bytes: {:?}", buffer);
//! println!("The bytes: {:?}", &buffer[..n]);
//! Ok(())
//! }
//! ```
Expand Down Expand Up @@ -537,7 +537,9 @@ pub trait Read {
/// let mut buffer = [0; 10];
///
/// // read up to 10 bytes
/// f.read(&mut buffer[..])?;
/// let n = f.read(&mut buffer[..])?;
///
/// println!("The bytes: {:?}", &buffer[..n]);
/// Ok(())
/// }
/// ```
Expand Down Expand Up @@ -1062,12 +1064,23 @@ impl Initializer {
/// use std::fs::File;
///
/// fn main() -> std::io::Result<()> {
/// let data = b"some bytes";
///
/// let mut pos = 0;
/// let mut buffer = File::create("foo.txt")?;
///
/// buffer.write(b"some bytes")?;
/// while pos < data.len() {
/// let bytes_written = buffer.write(&data[pos..])?;
/// pos += bytes_written;
/// }
/// Ok(())
/// }
/// ```
///
/// The trait also provides convenience methods like [`write_all`], which calls
/// `write` in a loop until its entire input has been written.
///
/// [`write_all`]: #method.write_all
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(spotlight)]
pub trait Write {
Expand Down