From 98a3b07213d695668081126a880fe7ac5dd9cd4e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 26 Jun 2020 13:31:36 +0200 Subject: [PATCH] Add missing Stdin and StdinLock exampels --- src/libstd/io/stdio.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index b65b150d2c3a1..2ad92f42690e8 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -218,9 +218,23 @@ fn handle_ebadf(r: io::Result, default: T) -> io::Result { /// [`BufRead`]: trait.BufRead.html /// /// ### Note: Windows Portability Consideration +/// /// 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 /// 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")] pub struct Stdin { inner: Arc>>>, @@ -236,9 +250,26 @@ pub struct Stdin { /// [`Stdin::lock`]: struct.Stdin.html#method.lock /// /// ### Note: Windows Portability Consideration +/// /// 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 /// 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")] pub struct StdinLock<'a> { inner: MutexGuard<'a, BufReader>>,