diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-14 13:19:20 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-14 13:19:20 -0700 |
| commit | 353df59893f4dc249f06047dca659b5b2172063f (patch) | |
| tree | 4c1b98110e30b6816f4e92be4494a1952957e0a7 | |
| parent | 2002ebacfbca288830a3c308ddc8189705c608fe (diff) | |
| parent | 98a3b07213d695668081126a880fe7ac5dd9cd4e (diff) | |
| download | rust-353df59893f4dc249f06047dca659b5b2172063f.tar.gz rust-353df59893f4dc249f06047dca659b5b2172063f.zip | |
Rollup merge of #73759 - GuillaumeGomez:stdin-examples, r=Dylan-DPC
Add missing Stdin and StdinLock examples r? @Dylan-DPC
| -rw-r--r-- | src/libstd/io/stdio.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index d6b7ad6254a..156f555be02 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -256,9 +256,23 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> { /// [`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<Mutex<BufReader<Maybe<StdinRaw>>>>, @@ -274,9 +288,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<Maybe<StdinRaw>>>, |
