formatx.rs

A macro for formatting non literal strings at runtime in Rust.

Getting Started

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.

Example

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

Alternatives

  1. strfmt
  2. runtime-fmt

License

Dual licensed under either of