After reading the std::io::BufReader
docs, I'm not sure how to best pass a BufReader
between functions. Multiple permutations are allowed, but which is best?
I have a function that takes a file:
use std::{fs::File, io::BufReader};
fn read_some_data(f: &mut std::fs::File) {
let mut reader = BufReader::new(f);
read_some_other_data(&mut reader);
}
While this can be made to work, which permutation of reference access should be used when passing the reader around to other functions?
&mut BufReader<&mut File>
BufReader<&mut File>
&mut BufReader<File>
BufReader<File>
Since there is no need for each function to own the data I was thinking it would be best to pass as &mut BufReader<&mut File>
, but the example in the docs uses <File>
.
Whats a good rule of thumb to use here?
While this example uses BufReader
, I assume the same answer would apply to BufWriter
too.