[ad_1]
As of Rust 1.58, you can take advantage of captured identifiers in format strings. That lets you do stuff like this:
let msg = "here";
let s = format!("Abc {msg}");
println!("Hi t{msg}");
println!("{s}");
This feature can be seen as a subset of string interpolation. Expressions like format!("Abc {a+b}")
are not supported and it’s unclear whether such a feature will ever be added. There have also been discussions on adding a subset of expressions for dotted paths, as in format!("Abc {foo.bar}")
.
Also note that the Rust 2021 Edition makes room for future additions to the language, such as f"hello {name}"
, which would allow for a much more concise string interpolation, comparable to most other modern languages.
[ad_2]