Allocating a fresh String per iteration to build messages that get discarded or appended.
format! is the obvious tool for interpolation, and the loop body reads cleanly.
Every format! call is a new heap allocation plus the formatter's per-call setup.
In a tight loop that's allocation traffic dominating the workload — and if the
result is just appended to a buffer, you've allocated twice for every line.
Reuse a single String buffer with write!(&mut buf, "...", ...) and buf.clear()
between iterations. For final concatenation reach for write! against the target
writer directly. Reserve format! for one-shot or cold-path messages.
Canonical alternative
performance/memory-optimization