Skip to content

Commit d7dac91

Browse files
committed
Allow only implementing Read::read_buf
1 parent 89e0576 commit d7dac91

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

library/std/src/io/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ where
549549
#[stable(feature = "rust1", since = "1.0.0")]
550550
#[doc(notable_trait)]
551551
#[cfg_attr(not(test), rustc_diagnostic_item = "IoRead")]
552+
#[rustc_must_implement_one_of(read, read_buf)]
552553
pub trait Read {
553554
/// Pull some bytes from this source into the specified buffer, returning
554555
/// how many bytes were read.
@@ -630,7 +631,10 @@ pub trait Read {
630631
/// }
631632
/// ```
632633
#[stable(feature = "rust1", since = "1.0.0")]
633-
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
634+
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
635+
let mut buf = BorrowedBuf::from(buf);
636+
self.read_buf(buf.unfilled()).map(|()| buf.len())
637+
}
634638

635639
/// Like `read`, except that it reads into a slice of buffers.
636640
///

0 commit comments

Comments
 (0)