Skip to content

Commit 9d01c46

Browse files
committed
core: Add iterable functions to io::reader_utils.
1 parent e7ca3e4 commit 9d01c46

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libcore/io.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,24 @@ impl reader_util for reader {
161161
while !self.eof() { buf += self.read_bytes(2048u); }
162162
buf
163163
}
164+
165+
fn each_byte(it: fn(int) -> bool) {
166+
while !self.eof() {
167+
if !it(self.read_byte()) { break; }
168+
}
169+
}
170+
171+
fn each_char(it: fn(char) -> bool) {
172+
while !self.eof() {
173+
if !it(self.read_char()) { break; }
174+
}
175+
}
176+
177+
fn each_line(it: fn(str) -> bool) {
178+
while !self.eof() {
179+
if !it(self.read_line()) { break; }
180+
}
181+
}
164182
}
165183

166184
// Reader implementations

0 commit comments

Comments
 (0)