Rollup merge of #60945 - blkerby:fill_buf_nll_doc_example, r=shepmaster

Simplify BufRead::fill_buf doc example using NLL

With non-lexical lifetimes, in this example it is no longer necessary to use a block to end the borrow early.
This commit is contained in:
Mazdak Farrokhzad 2019-05-19 02:31:44 +02:00 committed by GitHub
commit f9d58c7188
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1579,18 +1579,13 @@ pub trait BufRead: Read {
/// let stdin = io::stdin();
/// let mut stdin = stdin.lock();
///
/// // we can't have two `&mut` references to `stdin`, so use a block
/// // to end the borrow early.
/// let length = {
/// let buffer = stdin.fill_buf().unwrap();
/// let buffer = stdin.fill_buf().unwrap();
///
/// // work with buffer
/// println!("{:?}", buffer);
///
/// buffer.len()
/// };
/// // work with buffer
/// println!("{:?}", buffer);
///
/// // ensure the bytes we worked with aren't returned again later
/// let length = buffer.len();
/// stdin.consume(length);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]