Hi!
I recently had some headache trying to work around format!
, who only accepts string literals as first argument.
Basically, my use case is something like that:
fn message(language: &str, name: &str, number: i32) -> String {
let s = match language {
"french" => "Bonjour {}, le nombre est {}",
"spanish" => "Hola {}, el numero es {}",
_ => "Hi {}, the number is {}"
};
format!(s, name, number) //doesn't work: first argument to format! must be a string literal
}
The documentation I found explains quite clearly why the first argument to format!
must be a string literal, but I found it less clear what you are supposed if you can't have one. Is there an equivalent of format!
that checks the format string at runtime instead of compilation?
Thanks !