File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -883,6 +883,10 @@ pub trait Read {
883883 /// The yielded item is [`Ok`] if a byte was successfully read and [`Err`]
884884 /// otherwise. EOF is mapped to returning [`None`] from this iterator.
885885 ///
886+ /// The default implementation calls `read` for each byte,
887+ /// which can be very inefficient for data that's not in memory,
888+ /// such as [`File`]. Consider using a [`BufReader`] in such cases.
889+ ///
886890 /// # Examples
887891 ///
888892 /// [`File`]s implement `Read`:
@@ -895,10 +899,11 @@ pub trait Read {
895899 /// ```no_run
896900 /// use std::io;
897901 /// use std::io::prelude::*;
902+ /// use std::io::BufReader;
898903 /// use std::fs::File;
899904 ///
900905 /// fn main() -> io::Result<()> {
901- /// let f = File::open("foo.txt")?;
906+ /// let f = BufReader::new( File::open("foo.txt")?) ;
902907 ///
903908 /// for byte in f.bytes() {
904909 /// println!("{}", byte.unwrap());
You can’t perform that action at this time.
0 commit comments