Rollup merge of #73759 - GuillaumeGomez:stdin-examples, r=Dylan-DPC

Add missing Stdin and StdinLock examples

r? @Dylan-DPC
This commit is contained in:
Manish Goregaokar 2020-07-14 13:19:20 -07:00 committed by GitHub
commit 353df59893
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -256,9 +256,23 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
/// [`BufRead`]: trait.BufRead.html /// [`BufRead`]: trait.BufRead.html
/// ///
/// ### Note: Windows Portability Consideration /// ### Note: Windows Portability Consideration
///
/// When operating in a console, the Windows implementation of this stream does not support /// When operating in a console, the Windows implementation of this stream does not support
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return /// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
/// an error. /// an error.
///
/// # Examples
///
/// ```no_run
/// use std::io::{self, Read};
///
/// fn main() -> io::Result<()> {
/// let mut buffer = String::new();
/// let mut stdin = io::stdin(); // We get `Stdin` here.
/// stdin.read_to_string(&mut buffer)?;
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct Stdin { pub struct Stdin {
inner: Arc<Mutex<BufReader<Maybe<StdinRaw>>>>, inner: Arc<Mutex<BufReader<Maybe<StdinRaw>>>>,
@ -274,9 +288,26 @@ pub struct Stdin {
/// [`Stdin::lock`]: struct.Stdin.html#method.lock /// [`Stdin::lock`]: struct.Stdin.html#method.lock
/// ///
/// ### Note: Windows Portability Consideration /// ### Note: Windows Portability Consideration
///
/// When operating in a console, the Windows implementation of this stream does not support /// When operating in a console, the Windows implementation of this stream does not support
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return /// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
/// an error. /// an error.
///
/// # Examples
///
/// ```no_run
/// use std::io::{self, Read};
///
/// fn main() -> io::Result<()> {
/// let mut buffer = String::new();
/// let stdin = io::stdin(); // We get `Stdin` here.
/// {
/// let mut stdin_lock = stdin.lock(); // We get `StdinLock` here.
/// stdin_lock.read_to_string(&mut buffer)?;
/// } // `StdinLock` is dropped here.
/// Ok(())
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub struct StdinLock<'a> { pub struct StdinLock<'a> {
inner: MutexGuard<'a, BufReader<Maybe<StdinRaw>>>, inner: MutexGuard<'a, BufReader<Maybe<StdinRaw>>>,