See this example:
fn concat<T: std::fmt::Display>(s: &mut String, thing: T) {
// TODO
}
fn main() {
let mut s = "Hello ".into();
concat(&mut s, 42);
assert_eq!(&s, "Hello 42");
}
I know that I can use this:
s.push_str(&format!("{}", thing))
but this is not the most efficient, because format! allocate a String that is not necessary.
The most efficient is to write directly the string representation of the displayable item into the String buffer. How to do this?