Rust

Rust

Made by DeepSource

Usage of print! macro with newline RS-C1005

Anti-pattern
Minor

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! with println!
  • eprint! with eprintln!
  • write! with writeln!

Bad practice

print!("Hello, World!\n");

Recommended

println!("Hello, World!");