A macro for formatting non literal strings at runtime in Rust.
Add this to your Cargo.toml file.
toml
[dependencies]
formatx = "0.1"
Or add from command line.
bash
$ cargo add formatx@0.1
See docs and examples to know how to use it.
SOURCE: format! with non literal string
```rust use formatx::formatx;
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 {}", }; formatx!(s, name, number).unwrap() }
fn main() { println!("{}", message("french", "Léa", 1)); println!("{}", message("spanish", "Sofia", 2)); println!("{}", message("english", "Ashley", 3)); } ```
OUTPUT
Bonjour Léa, le nombre est 1
Hola Sofia, el numero es 2
Hi Ashley, the number is 3
Dual licensed under either of