@@ -218,9 +218,23 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
218
218
/// [`BufRead`]: trait.BufRead.html
219
219
///
220
220
/// ### Note: Windows Portability Consideration
221
+ ///
221
222
/// When operating in a console, the Windows implementation of this stream does not support
222
223
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
223
224
/// an error.
225
+ ///
226
+ /// # Examples
227
+ ///
228
+ /// ```no_run
229
+ /// use std::io::{self, Read};
230
+ ///
231
+ /// fn main() -> io::Result<()> {
232
+ /// let mut buffer = String::new();
233
+ /// let mut stdin = io::stdin(); // We get `Stdin` here.
234
+ /// stdin.read_to_string(&mut buffer)?;
235
+ /// Ok(())
236
+ /// }
237
+ /// ```
224
238
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
225
239
pub struct Stdin {
226
240
inner : Arc < Mutex < BufReader < Maybe < StdinRaw > > > > ,
@@ -236,9 +250,26 @@ pub struct Stdin {
236
250
/// [`Stdin::lock`]: struct.Stdin.html#method.lock
237
251
///
238
252
/// ### Note: Windows Portability Consideration
253
+ ///
239
254
/// When operating in a console, the Windows implementation of this stream does not support
240
255
/// non-UTF-8 byte sequences. Attempting to read bytes that are not valid UTF-8 will return
241
256
/// an error.
257
+ ///
258
+ /// # Examples
259
+ ///
260
+ /// ```no_run
261
+ /// use std::io::{self, Read};
262
+ ///
263
+ /// fn main() -> io::Result<()> {
264
+ /// let mut buffer = String::new();
265
+ /// let stdin = io::stdin(); // We get `Stdin` here.
266
+ /// {
267
+ /// let mut stdin_lock = stdin.lock(); // We get `StdinLock` here.
268
+ /// stdin_lock.read_to_string(&mut buffer)?;
269
+ /// } // `StdinLock` is dropped here.
270
+ /// Ok(())
271
+ /// }
272
+ /// ```
242
273
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
243
274
pub struct StdinLock < ' a > {
244
275
inner : MutexGuard < ' a , BufReader < Maybe < StdinRaw > > > ,
0 commit comments