trait

fmt::Write: text destinations

Use fmt::Write for UTF-8 text sinks such as String, not for arbitrary byte streams. The methods return a formatting result. Expected stdout (not executed): item=3! Common mistake: Confusing fmt::Write with io::Write, which supports byte-oriented I/O and flushing.

Formal Syntax & Structure

rust syntaxrust
fn write_str(&mut self, s: &str) -> fmt::Result

Working Example

Example Snippetrust
fn main() {    use std::fmt::Write;    let mut s = String::new();    write!(&mut s, "item={}", 3).unwrap();    s.write_char('!').unwrap();    println!("{s}");}
Rust Reference