I write some content into the file using this code in rust:
fn renderBody(w:&mut File,doc: &Vec<UserDictResponse>) {
for word in doc {
let word_content = format!("{}{}{}", r"\textbf{", word.word.to_string(),r"}");
writeln!(w,"{}",word_content);
writeln!(w,r"");
let translate = format!("{}",word.translation.to_string());
writeln!(w,"{}",translate);
writeln!(w,r"");
writeln!(w,r"\vspace{{12pt}}");
writeln!(w,r"");
}
}
when I compile this code, shows warning like this:
warning: unused `Result` that must be used
--> src/service/word/user_dict_service.rs:116:9
|
116 | writeln!(w,r"\vspace{{12pt}}");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: this warning originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info)
warning: unused `Result` that must be used
--> src/service/word/user_dict_service.rs:117:9
|
117 | writeln!(w,r"");
| ^^^^^^^^^^^^^^^^
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: this warning originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info)
I should handle the Err when using write? I did not return any Result, what should I do to handle the result properly? I make a minimal example like this:
use std::fs::File;
use std::io::Write;
fn main() {
let path = "/home/dolphin/demo.tex";
let mut file = File::create(path).unwrap();
writeln!(&mut file, r"\documentclass[12pt]{{book}}").unwrap();
}
when I compile, it did not have warning. This makes me confusing.