String formatting

Creating strings is easy: you just call String::new() and then use a static string or add characters to it. Sometimes, you might want easier access to how the string gets created. If you, for example, want the string to say Hello {user}!, even though you can probably do something such as creating a String with Hello in it, then appending the username and then the exclamation mark, this is not ideal.

This is where the std::fmt module comes in handy, with its format!() macro and all of its formatting options. These options apply to console printing, string formatting, and even buffer writing with write!() and writeln!() macros. You can find the complete guide in the std::fmt module documentation at the standard library documentation, ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.