@@ -78,14 +78,11 @@ pub struct Empty { _priv: () }
7878/// A slightly sad example of not reading anything into a buffer:
7979///
8080/// ```
81- /// use std::io;
82- /// use std::io::Read;
81+ /// use std::io::{self, Read};
8382///
84- /// # fn foo() -> io::Result<String> {
8583/// let mut buffer = String::new();
86- /// try!(io::empty().read_to_string(&mut buffer));
87- /// # Ok(buffer)
88- /// # }
84+ /// io::empty().read_to_string(&mut buffer).unwrap();
85+ /// assert!(buffer.is_empty());
8986/// ```
9087#[ stable( feature = "rust1" , since = "1.0.0" ) ]
9188pub fn empty ( ) -> Empty { Empty { _priv : ( ) } }
@@ -113,6 +110,16 @@ pub struct Repeat { byte: u8 }
113110///
114111/// All reads from this reader will succeed by filling the specified buffer with
115112/// the given byte.
113+ ///
114+ /// # Examples
115+ ///
116+ /// ```
117+ /// use std::io::{self, Read};
118+ ///
119+ /// let mut buffer = [0; 3];
120+ /// io::repeat(0b101).read_exact(&mut buffer).unwrap();
121+ /// assert_eq!(buffer, [0b101, 0b101, 0b101]);
122+ /// ```
116123#[ stable( feature = "rust1" , since = "1.0.0" ) ]
117124pub fn repeat ( byte : u8 ) -> Repeat { Repeat { byte : byte } }
118125
@@ -139,6 +146,16 @@ pub struct Sink { _priv: () }
139146///
140147/// All calls to `write` on the returned instance will return `Ok(buf.len())`
141148/// and the contents of the buffer will not be inspected.
149+ ///
150+ /// # Examples
151+ ///
152+ /// ```rust
153+ /// use std::io::{self, Write};
154+ ///
155+ /// let mut buffer = vec![1, 2, 3, 5, 8];
156+ /// let num_bytes = io::sink().write(&mut buffer).unwrap();
157+ /// assert_eq!(num_bytes, 5);
158+ /// ```
142159#[ stable( feature = "rust1" , since = "1.0.0" ) ]
143160pub fn sink ( ) -> Sink { Sink { _priv : ( ) } }
144161
0 commit comments