@@ -1001,6 +1001,30 @@ impl<'r, T: Buffer> Iterator<~str> for Lines<'r, T> {
1001
1001
}
1002
1002
}
1003
1003
1004
+ /// An iterator that reads a utf8-encoded character on each iteration,
1005
+ /// until `.read_char()` returns `None`.
1006
+ ///
1007
+ /// # Notes about the Iteration Protocol
1008
+ ///
1009
+ /// The `Chars` may yield `None` and thus terminate
1010
+ /// an iteration, but continue to yield elements if iteration
1011
+ /// is attempted again.
1012
+ ///
1013
+ /// # Error
1014
+ ///
1015
+ /// This iterator will swallow all I/O errors, transforming `Err` values to
1016
+ /// `None`. If errors need to be handled, it is recommended to use the
1017
+ /// `read_char` method directly.
1018
+ pub struct Chars < ' r , T > {
1019
+ priv buffer : & ' r mut T
1020
+ }
1021
+
1022
+ impl < ' r , T : Buffer > Iterator < char > for Chars < ' r , T > {
1023
+ fn next ( & mut self ) -> Option < char > {
1024
+ self . buffer . read_char ( ) . ok ( )
1025
+ }
1026
+ }
1027
+
1004
1028
/// A Buffer is a type of reader which has some form of internal buffering to
1005
1029
/// allow certain kinds of reading operations to be more optimized than others.
1006
1030
/// This type extends the `Reader` trait with a few methods that are not
@@ -1146,6 +1170,17 @@ pub trait Buffer: Reader {
1146
1170
None => Err ( standard_error ( InvalidInput ) )
1147
1171
}
1148
1172
}
1173
+
1174
+ /// Create an iterator that reads a utf8-encoded character on each iteration until EOF.
1175
+ ///
1176
+ /// # Error
1177
+ ///
1178
+ /// This iterator will transform all error values to `None`, discarding the
1179
+ /// cause of the error. If this is undesirable, it is recommended to call
1180
+ /// `read_char` directly.
1181
+ fn chars < ' r > ( & ' r mut self ) -> Chars < ' r , Self > {
1182
+ Chars { buffer : self }
1183
+ }
1149
1184
}
1150
1185
1151
1186
pub enum SeekStyle {
0 commit comments