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, by running rustup doc --open.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.4