macro

writeln! — Append a formatted line to a writer

Like write!, but appends a single LF newline, even on Windows. The destination may be a text buffer or an I/O writer. For real I/O, propagate or handle the returned error. Expression result: writer-dependent result. Expected result (not executed): stdout: 'Name: Mina\nTasks: 3\n'; no stderr. Common mistake: Adding a newline to the template as well, causing two line breaks.

Formal Syntax & Structure

rust syntaxrust
writeln!(destination, "format string", arguments...)

Working Example

Example Snippetrust
use std::fmt::Write as _;fn main() {    let mut report = String::new();    writeln!(&mut report, "Name: Mina").unwrap();    writeln!(&mut report, "Tasks: 3").unwrap();    print!("{report}");}
Rust Reference