Hello,
I tried to pass a borrowed CSV writer to a function.
I search and, I found a similar topic here, but in this case he doesn't pass a borrowed writer.
I try to do this :
use std::io;
fn write_record<W: io::Write>(wtr: &mut csv::Writer<W>) {
wtr.write_record(&["toto"]).unwrap();
}
fn main() {
let mut wtr = csv::Writer::from_path("./toto.csv").unwrap();
for _i in 1..5 {
write_record(&wtr);
}
}
But I have a “mismatched types” on the “write_record(&wtr)" line.
error[E0308]: mismatched types
--> src/main.rs:10:22
|
10 | write_record(&wtr);
| ------------ ^^^^ types differ in mutability
| |
| arguments to this function are incorrect
|
= note: expected mutable reference `&mut Writer<_>`
found reference `&Writer<File>`
Why this is not working ? And how can I fix it ?