Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of FromIterator<String, RevLinesError> #22

Open
xTriixrx opened this issue Mar 17, 2025 · 0 comments
Open

Implementation of FromIterator<String, RevLinesError> #22

xTriixrx opened this issue Mar 17, 2025 · 0 comments

Comments

@xTriixrx
Copy link

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()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant