Skip to content

Commit

Permalink
Allow only implementing Read::read_buf
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Jan 9, 2023
1 parent 89e0576 commit d7dac91
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ where
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(notable_trait)]
#[cfg_attr(not(test), rustc_diagnostic_item = "IoRead")]
#[rustc_must_implement_one_of(read, read_buf)]
pub trait Read {
/// Pull some bytes from this source into the specified buffer, returning
/// how many bytes were read.
Expand Down Expand Up @@ -630,7 +631,10 @@ pub trait Read {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
let mut buf = BorrowedBuf::from(buf);
self.read_buf(buf.unfilled()).map(|()| buf.len())
}

/// Like `read`, except that it reads into a slice of buffers.
///
Expand Down

0 comments on commit d7dac91

Please sign in to comment.