Function lines::linemapper::map_lines
[−]
[src]
pub fn map_lines<R, F>(r: R, f: F) -> Result<()> where
R: BufRead,
F: FnMut(&[u8]) -> bool,
Maps the given function f
over lines read from r
until either
the function returns false
, the end of stream is encountered, or
the underlying reader returns an error.
Examples
Count the number of lines with more than 80 bytes:
let r: BufRead = ...;
let mut nl = 0usize;
map_lines(r, |line| {
if line.len() > 80 {
nl += 1;
}
true
});
println!("long lines: {}", nl);