expression
Separate result records from diagnostics
Standard output carries results; standard error carries diagnostics. Keeping them separate lets scripts capture data without parsing human-facing messages. Flush explicitly and propagate write errors. The test runner captures both streams separately. Fixture: Expected stdout (not executed): count=2 Expected stderr: 'processed input\n' Expected exit: 0 Common mistake: Assuming captured stdout and stderr have a reliable combined ordering.
Formal Syntax & Structure
rust syntaxrust
writeln!(stdout, ...)?; writeln!(stderr, ...)?;Working Example
Example Snippetrust
fn main() -> std::io::Result<()> { use std::io::{self, Write}; let mut out = io::stdout().lock(); let mut err = io::stderr().lock(); writeln!(out, "count=2")?; out.flush()?; writeln!(err, "processed input")?; err.flush()?; Ok(())}