File tree 1 file changed +6
-1
lines changed
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -883,6 +883,10 @@ pub trait Read {
883
883
/// The yielded item is [`Ok`] if a byte was successfully read and [`Err`]
884
884
/// otherwise. EOF is mapped to returning [`None`] from this iterator.
885
885
///
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
+ ///
886
890
/// # Examples
887
891
///
888
892
/// [`File`]s implement `Read`:
@@ -895,10 +899,11 @@ pub trait Read {
895
899
/// ```no_run
896
900
/// use std::io;
897
901
/// use std::io::prelude::*;
902
+ /// use std::io::BufReader;
898
903
/// use std::fs::File;
899
904
///
900
905
/// fn main() -> io::Result<()> {
901
- /// let f = File::open("foo.txt")?;
906
+ /// let f = BufReader::new( File::open("foo.txt")?) ;
902
907
///
903
908
/// for byte in f.bytes() {
904
909
/// println!("{}", byte.unwrap());
You can’t perform that action at this time.
0 commit comments