#[test]
fn read_test() {
let mut f = BufReader::new(
File::open("/home/ssss/.bashrc").unwrap()
);
let mut buf = Vec::with_capacity(8192);
let r = |f: &mut BufReader<File>, buf:&mut Vec<u8>| f.by_ref().take(1024).read_to_end(buf).map(|n| {
println!("n={}", n);
n > 0
});
// r(&mut f, &mut buf);
// r(&mut f, &mut buf);
while let Ok(true) = r(&mut f, &mut buf) {
println!(">>\n{}\n<<", String::from_utf8_lossy(&buf));
buf.clear();
}
}
Hi.
Today I found something that made me wonder why.
In the above code works, but when removing the type annotation of buf
in the closure, compiler says mutable borrow occur more than once
What is the difference between having and not having a type annotation in closure capturing?