print! vs println!
print! and println! both write formatted text to standard output. The difference is the newline: println! appends one, while print! leaves the cursor immediately after the formatted text.
print!("building...");
println!(" done");Prefer println! for complete lines
Section titled “Prefer println! for complete lines”For ordinary terminal output, println! is the default. It produces a complete line and works naturally with line-buffered stdout.
Rust documents the newline emitted by println! as a line feed (\n) on every platform.
Use print! when the line must stay open
Section titled “Use print! when the line must stay open”print! is useful for prompts, progress fragments, and output that intentionally continues on the same line. The important catch is buffering.
When stdout is connected to a terminal it is commonly line-buffered, so output without a newline may remain in the buffer. If the user must see the text immediately, flush stdout explicitly.
Repeated writes
Section titled “Repeated writes”Both macros lock stdout on each call. For occasional output that is exactly what you want. In a hot loop, repeatedly acquiring the lock can become avoidable overhead.
Lock stdout once and use write! or writeln! through the locked handle when you have many writes. The output macros overview contains a CI-checked example of that pattern.
Primary output only
Section titled “Primary output only”The standard library documentation positions these macros for primary program output. If text is an error, warning, or progress message that should stay separate from piped data, use stderr through eprint! or eprintln!.