rev_lines
rev_lines copied to clipboard
Implementation of FromIterator<String, RevLinesError>
I am using this library to get the first N amount of lines from a file in reverse... my current implementation is this:
fn lines_from_file(file: &File, limit: usize) -> Vec<String> {
let mut vec = vec![];
let rev_lines = RevLines::new(file);
for (i, line) in rev_lines.enumerate() {
match line {
Ok(line) => vec.push(line),
Err(e) => panic!("RevLinesError in lines_from_file: {}", e),
}
if i == limit {
break;
}
}
return vec;
}
Ideally, if the FromIterator<String, RevLinesError> interface was implemented I could do roughly something like this:
fn lines_from_file(file: &File, limit: usize) -> Vec<String> {
let rev_lines = RevLines::new(file);
rev_lines.take(limit).collect()
}