2 Detects cases where the result of a `format!` call is
3 appended to an existing `String`.
6 Introduces an extra, avoidable heap allocation.
9 `format!` returns a `String` but `write!` returns a `Result`.
10 Thus you are forced to ignore the `Err` variant to achieve the same API.
12 While using `write!` in the suggested way should never fail, this isn't necessarily clear to the programmer.
16 let mut s = String::new();
17 s += &format!("0x{:X}", 1024);
18 s.push_str(&format!("0x{:X}", 1024));
22 use std::fmt::Write as _; // import without risk of name clashing
24 let mut s = String::new();
25 let _ = write!(s, "0x{:X}", 1024);