[rust-dev] Mutable files

David Henningsson diwic at ubuntu.com
Sun Jul 20 18:29:14 PDT 2014


Hi,

Consider these two examples:

1)

let mut file = File::open(filename);
file.read(buf);

2)

let file = File::open(filename);
let mut reader = BufferedReader::new(file);
reader.read(buf);

My question is: in example 2, why doesn't BufferedReader need "file" to 
be mutable? After all, BufferedReader ends up calling file.read(), which 
needs a mutable reference to the file.

It looks like I'm able to "bypass" the mutability requirement, just 
because I wrap the file inside a BufferedReader?

// David


More information about the Rust-dev mailing list