From 9d01c46c07c2418ae5c26f03785c350185b17ed0 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Tue, 1 May 2012 08:14:56 -0700 Subject: [PATCH] core: Add iterable functions to io::reader_utils. --- src/libcore/io.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libcore/io.rs b/src/libcore/io.rs index beac1e5fb09..e210ab0944c 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -161,6 +161,24 @@ impl reader_util for reader { while !self.eof() { buf += self.read_bytes(2048u); } buf } + + fn each_byte(it: fn(int) -> bool) { + while !self.eof() { + if !it(self.read_byte()) { break; } + } + } + + fn each_char(it: fn(char) -> bool) { + while !self.eof() { + if !it(self.read_char()) { break; } + } + } + + fn each_line(it: fn(str) -> bool) { + while !self.eof() { + if !it(self.read_line()) { break; } + } + } } // Reader implementations