Add mention of BufReader
in Read::bytes
docs
This commit is contained in:
parent
d70c0ecfae
commit
8509936e8f
1 changed files with 6 additions and 1 deletions
|
@ -883,6 +883,10 @@ pub trait Read {
|
||||||
/// The yielded item is [`Ok`] if a byte was successfully read and [`Err`]
|
/// The yielded item is [`Ok`] if a byte was successfully read and [`Err`]
|
||||||
/// otherwise. EOF is mapped to returning [`None`] from this iterator.
|
/// otherwise. EOF is mapped to returning [`None`] from this iterator.
|
||||||
///
|
///
|
||||||
|
/// The default implementation calls `read` for each byte,
|
||||||
|
/// which can be very inefficient for data that's not in memory,
|
||||||
|
/// such as [`File`]. Consider using a [`BufReader`] in such cases.
|
||||||
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// [`File`]s implement `Read`:
|
/// [`File`]s implement `Read`:
|
||||||
|
@ -895,10 +899,11 @@ pub trait Read {
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use std::io;
|
/// use std::io;
|
||||||
/// use std::io::prelude::*;
|
/// use std::io::prelude::*;
|
||||||
|
/// use std::io::BufReader;
|
||||||
/// use std::fs::File;
|
/// use std::fs::File;
|
||||||
///
|
///
|
||||||
/// fn main() -> io::Result<()> {
|
/// fn main() -> io::Result<()> {
|
||||||
/// let f = File::open("foo.txt")?;
|
/// let f = BufReader::new(File::open("foo.txt")?);
|
||||||
///
|
///
|
||||||
/// for byte in f.bytes() {
|
/// for byte in f.bytes() {
|
||||||
/// println!("{}", byte.unwrap());
|
/// println!("{}", byte.unwrap());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue