Closed
Description
When trying to compile this code:
pub fn write_to_log(line: String) {
use std::fs::{File, OpenOptions};
let resFile = OpenOptions::new().read(true).write(true)
.append(true).open("log.log");
let mut file = match resFile {
Ok(f) => f,
Err(e) => panic!("file error: {}", e),
};
let _ = writeln!(&mut file, "{}", line);
}
fn main() {
write_to_log("Hello".to_string());
}
compiler prints this message:
<std macros>:2:20: 2:66 error: type `&mut std::fs::File` does not implement any method in scope named `write_fmt`
<std macros>:2 ( & mut * $ dst ) . write_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<std macros>:2:66: 2:66 help: methods from traits can only be called if the trait is in scope; the following trait is implemented but not in scope, perhaps add a `use` for it:
<std macros>:2:66: 2:66 help: candidate #1: use `std::io::Write`
error: aborting due to previous error
I would expect it to point me to the fine and line where writeln!
is used. Right now it very hard to find error location.