@@ -256,9 +256,23 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
256
256
/// [`BufRead`]: trait.BufRead.html
257
257
///
258
258
/// ### Note: Windows Portability Consideration
259
+ ///
259
260
/// When operating in a console, the Windows implementation of this stream does not support
260
261
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
261
262
/// an error.
263
+ ///
264
+ /// # Examples
265
+ ///
266
+ /// ```no_run
267
+ /// use std::io::{self, Read};
268
+ ///
269
+ /// fn main() -> io::Result<()> {
270
+ /// let mut buffer = String::new();
271
+ /// let mut stdin = io::stdin(); // We get `Stdin` here.
272
+ /// stdin.read_to_string(&mut buffer)?;
273
+ /// Ok(())
274
+ /// }
275
+ /// ```
262
276
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
263
277
pub struct Stdin {
264
278
inner : Arc < Mutex < BufReader < Maybe < StdinRaw > > > > ,
@@ -274,9 +288,26 @@ pub struct Stdin {
274
288
/// [`Stdin::lock`]: struct.Stdin.html#method.lock
275
289
///
276
290
/// ### Note: Windows Portability Consideration
291
+ ///
277
292
/// When operating in a console, the Windows implementation of this stream does not support
278
293
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
279
294
/// an error.
295
+ ///
296
+ /// # Examples
297
+ ///
298
+ /// ```no_run
299
+ /// use std::io::{self, Read};
300
+ ///
301
+ /// fn main() -> io::Result<()> {
302
+ /// let mut buffer = String::new();
303
+ /// let stdin = io::stdin(); // We get `Stdin` here.
304
+ /// {
305
+ /// let mut stdin_lock = stdin.lock(); // We get `StdinLock` here.
306
+ /// stdin_lock.read_to_string(&mut buffer)?;
307
+ /// } // `StdinLock` is dropped here.
308
+ /// Ok(())
309
+ /// }
310
+ /// ```
280
311
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
281
312
pub struct StdinLock < ' a > {
282
313
inner : MutexGuard < ' a , BufReader < Maybe < StdinRaw > > > ,
0 commit comments