In this lesson we take a look at how println!()
can be used to output multiple variables using formatter placeholders.
This example only compounds my question from the previous video where only one variable was involved. Why add the variables separately from where they will be used in the string? Why doesn't Rust do something like println!("{name} and {another_name}");
instead?
Please see my comment in the other lesson: https://egghead.io/lessons/rust-variables-and-mutability-in-rust
Also, I know it's not exactly the same, but you can do named interpolation as well (at least in format!()
):
format!("{argument}", argument = "test");