println! and format!
Printing is handled by a series of [macros][macros] defined in [std::fmt][fmt] Some of which include:
format!: write formatted text to [String][string]print!: same asformat!but the text is printed to the console (io::stdout).println!: same asprint!but a newline is appended.eprint!: same asformat!but the text is printed to the standard error (io::stderr).eprintln!: same aseprint!but a newline is appended.
All parse text in the same fashion. As a plus, Rust checks format correctness at compile time.
format!
1.🌟
2. fn main() {
3. let s1 = "hello";
4. /* Fill in the blank */
5. let s = format!(__);
6. assert_eq!(s, "hello, world!");
7. }
print!, println!
2.🌟
2. fn main() {
3. /* Fill in the blanks to make it print:
4. Hello world, I am
5. Sunface!
6. */
7. __("hello world, ");
8. __("I am");
9. __("Sunface!");
10. }
You can find the solutions here(under the solutions path), but only use it when you need it :)
