I don't really know how to help you rather than providing the code I'd write for it, so:
fn read_last_n_lines(path: impl AsRef<Path>, n: usize) -> Vec<String> {
// it's simpler to use the provided helper function than dealing with the File ourselves
let s = std::fs::read_to_string(path).unwrap();
// we collect all the lines into a vec
let s = s.lines().collect::<Vec<_>>();
// then take only the last n lines
s[s.len().saturating_sub(n)..s.len()].iter().map(|&s| String::from(s)).collect()
}
If there's anything unclear about the code above, feel free to ask me any questions about it
Still trying to understand some of the lower levels of rust. Wouldn't s contain the entire contents of the file? Most times that's not problematic, but I'm work with potentially files large than my RAM.
Yes. If you want to actually read only the last n lines of data from the file I think you'll have to write the code for that yourself. As far as I know the standard library doesn't have any facilities for reading lines from the end of a file back towards the beginning.