I don't understand why Rust does not allow to format a const string. This program does not compile:
const CON: &str = "test {}";
fn main() {
println!(CON, 4);
}
It generates the following error:
error: format argument must be a string literal
--> a.rs:4:14
|
4 | println!(CON, 4);
| ^^^
help: you might be missing a string literal to format with
|
4 | println!("{} {}", CON, 4);
| ^^^^^^^^
error: aborting due to previous error
I read around that println!
and format!
only work when the first argument is a string literal. But a const
string is a named string literal.