The given examples are not really usable for a big file, because it will scan the entire file to the end.
You will have to seek to some position close to the end of the file, read a chunk, do with it whatever you need to do, and repeat.
No guarantees here, I'm just scribbling this down for reference:
let mut f = File::open("foo.txt").unwrap();
let mut buffer = String::new();
// Determine file size.
let file_size = f.metadata().unwrap().len();
// read last 10240 bytes. Adapt this for your requirements.
let chunk_size = 10240;
let start_pos = if file_size < chunk_size { 0 } else { file_size - chunk_size };
// Seek to end of file - chunk_size.
f.seek(std::io::SeekFrom::Start(start_pos)).unwrap();
// Read to buffer.
f.take(chunk_size).read_to_string(&mut buffer).unwrap();
let mut lines = buffer.lines();
// The first line is probably a partial line now, cut off in the middle.
// Safe it for now...
let first_line = lines.next().unwrap();
// Do whatever with the actual lines.
for line in lines { println!("{}", line.unwrap()); }
// Repeat process by seeking back by chunk_size again.
// Note that you now have to merge the last line of the new buffer contents with the previous first_line...
.....
...
If you wrap this up in a nice struct it's not so bad. ![]()