3 ms·
In previous Rust versions, you can't print {0} by printing `{x}`. Adding braces around variables turns them into named variables. For example: pub fn main(
by jeroenhd 5y ago
In previous Rust versions, you can't print {0} by printing `{x}`. Adding braces around variables turns them into named variables. For example:
pub fn main() {
let y = 4;
println!("{x}", x=y);
}
To print '{x}', you need to write:
pub fn main() {
let x = 4; // unused
println!("{{x}}");
}
- estebank 5y agoThe last bit of information that GP might be missing is that pub fn main() { let x = 4; // unused println!("{x}"); } would previously be a compile time error (because the format! family of macros perform string interpolation at compile time): error: there is no argument named `x` --> <source>:3:15 | 3 | println!("{x}"); | ^^^ So no new existing code will stop compiling, some things that were previously compile errors will now work.