Mut String += format_args!(…);

write! is quite magical for Rust. It is completely duck-typed — it doesn't use Write traits, it takes anything that compiles with .write_fmt(args) appended to it. It doesn't even care about the function type or return type. It takes even bogus signatures like fn write_fmt(&self, f: impl Sized) -> ().

Compared to that format_args! is pretty tame and well-behaved.

If format_args! could be made to borrow its arguments for a longer lifetime… (eh, can't).

8 Likes