Using
write!()
with a format string that ends in a single newline 33 for col in row {
34 write!(f, " {} ", col)?;
35 }
36 write!(f, "\n")?; 37 }
38 Ok(())
39 }
Description
Several macros in the standard library such as print!
and eprint!
have
analogous macros such as println!
and eprintln!
that append a newline. Instead of
calling print!
with an explicit newline character at the end of the format string,
prefer its alternative, println!
.
Remove the trailing newline character from the original format string and replace the macro call with its analog:
print!
withprintln!
eprint!
witheprintln!
write!
withwriteln!
Bad practice
print!("Hello, World!\n");
Recommended
println!("Hello, World!");