@@ -31,7 +31,7 @@ Some examples of obvious things you might want to do
3131 use std::io;
3232
3333 for line in io::stdin().lines() {
34- print!("{}", line);
34+ print!("{}", line.unwrap() );
3535 }
3636 ```
3737
@@ -57,26 +57,26 @@ Some examples of obvious things you might want to do
5757
5858* Iterate over the lines of a file
5959
60- ```rust
60+ ```rust,no_run
6161 use std::io::BufferedReader;
6262 use std::io::File;
6363
6464 let path = Path::new("message.txt");
6565 let mut file = BufferedReader::new(File::open(&path));
6666 for line in file.lines() {
67- print!("{}", line);
67+ print!("{}", line.unwrap() );
6868 }
6969 ```
7070
7171* Pull the lines of a file into a vector of strings
7272
73- ```rust
73+ ```rust,no_run
7474 use std::io::BufferedReader;
7575 use std::io::File;
7676
7777 let path = Path::new("message.txt");
7878 let mut file = BufferedReader::new(File::open(&path));
79- let lines: ~[~str] = file.lines().collect();
79+ let lines: ~[~str] = file.lines().map(|x| x.unwrap()). collect();
8080 ```
8181
8282* Make a simple TCP client connection and request
@@ -466,10 +466,8 @@ pub trait Reader {
466466 ///
467467 /// # Error
468468 ///
469- /// The iterator protocol causes all specifics about errors encountered to
470- /// be swallowed. All errors will be signified by returning `None` from the
471- /// iterator. If this is undesirable, it is recommended to use the
472- /// `read_byte` method.
469+ /// Any error other than `EndOfFile` that is produced by the underlying Reader
470+ /// is returned by the iterator and should be handled by the caller.
473471 fn bytes < ' r > ( & ' r mut self ) -> extensions:: Bytes < ' r , Self > {
474472 extensions:: Bytes :: new ( self )
475473 }
@@ -986,7 +984,7 @@ pub trait Stream: Reader + Writer { }
986984impl < T : Reader + Writer > Stream for T { }
987985
988986/// An iterator that reads a line on each iteration,
989- /// until `.read_line()` returns `None `.
987+ /// until `.read_line()` encounters `EndOfFile `.
990988///
991989/// # Notes about the Iteration Protocol
992990///
@@ -996,21 +994,24 @@ impl<T: Reader + Writer> Stream for T {}
996994///
997995/// # Error
998996///
999- /// This iterator will swallow all I/O errors, transforming `Err` values to
1000- /// `None`. If errors need to be handled, it is recommended to use the
1001- /// `read_line` method directly.
997+ /// Any error other than `EndOfFile` that is produced by the underlying Reader
998+ /// is returned by the iterator and should be handled by the caller.
1002999pub struct Lines < ' r , T > {
10031000 priv buffer : & ' r mut T ,
10041001}
10051002
1006- impl < ' r , T : Buffer > Iterator < ~str > for Lines < ' r , T > {
1007- fn next ( & mut self ) -> Option < ~str > {
1008- self . buffer . read_line ( ) . ok ( )
1003+ impl < ' r , T : Buffer > Iterator < IoResult < ~str > > for Lines < ' r , T > {
1004+ fn next ( & mut self ) -> Option < IoResult < ~str > > {
1005+ match self . buffer . read_line ( ) {
1006+ Ok ( x) => Some ( Ok ( x) ) ,
1007+ Err ( IoError { kind : EndOfFile , ..} ) => None ,
1008+ Err ( y) => Some ( Err ( y) )
1009+ }
10091010 }
10101011}
10111012
10121013/// An iterator that reads a utf8-encoded character on each iteration,
1013- /// until `.read_char()` returns `None `.
1014+ /// until `.read_char()` encounters `EndOfFile `.
10141015///
10151016/// # Notes about the Iteration Protocol
10161017///
@@ -1020,16 +1021,19 @@ impl<'r, T: Buffer> Iterator<~str> for Lines<'r, T> {
10201021///
10211022/// # Error
10221023///
1023- /// This iterator will swallow all I/O errors, transforming `Err` values to
1024- /// `None`. If errors need to be handled, it is recommended to use the
1025- /// `read_char` method directly.
1024+ /// Any error other than `EndOfFile` that is produced by the underlying Reader
1025+ /// is returned by the iterator and should be handled by the caller.
10261026pub struct Chars < ' r , T > {
10271027 priv buffer : & ' r mut T
10281028}
10291029
1030- impl < ' r , T : Buffer > Iterator < char > for Chars < ' r , T > {
1031- fn next ( & mut self ) -> Option < char > {
1032- self . buffer . read_char ( ) . ok ( )
1030+ impl < ' r , T : Buffer > Iterator < IoResult < char > > for Chars < ' r , T > {
1031+ fn next ( & mut self ) -> Option < IoResult < char > > {
1032+ match self . buffer . read_char ( ) {
1033+ Ok ( x) => Some ( Ok ( x) ) ,
1034+ Err ( IoError { kind : EndOfFile , ..} ) => None ,
1035+ Err ( y) => Some ( Err ( y) )
1036+ }
10331037 }
10341038}
10351039
@@ -1095,9 +1099,8 @@ pub trait Buffer: Reader {
10951099 ///
10961100 /// # Error
10971101 ///
1098- /// This iterator will transform all error values to `None`, discarding the
1099- /// cause of the error. If this is undesirable, it is recommended to call
1100- /// `read_line` directly.
1102+ /// Any error other than `EndOfFile` that is produced by the underlying Reader
1103+ /// is returned by the iterator and should be handled by the caller.
11011104 fn lines < ' r > ( & ' r mut self ) -> Lines < ' r , Self > {
11021105 Lines { buffer : self }
11031106 }
@@ -1183,9 +1186,8 @@ pub trait Buffer: Reader {
11831186 ///
11841187 /// # Error
11851188 ///
1186- /// This iterator will transform all error values to `None`, discarding the
1187- /// cause of the error. If this is undesirable, it is recommended to call
1188- /// `read_char` directly.
1189+ /// Any error other than `EndOfFile` that is produced by the underlying Reader
1190+ /// is returned by the iterator and should be handled by the caller.
11891191 fn chars < ' r > ( & ' r mut self ) -> Chars < ' r , Self > {
11901192 Chars { buffer : self }
11911193 }
0 commit comments