| Crates.io | safe_format |
| lib.rs | safe_format |
| version | 0.1.5 |
| created_at | 2024-07-09 09:43:31.783264+00 |
| updated_at | 2024-07-09 12:42:56.434857+00 |
| description | safe_format! macro works similarly to the built-in format! macro but allows for named parameters and it safely ignores any extra parameters that are not used in format string |
| homepage | https://github.com/AllenDang/safe_format |
| repository | https://github.com/AllenDang/safe_format |
| max_upload_size | |
| id | 1296861 |
| size | 18,250 |
safe_format is a procedural macro for Rust that allows you to safely format strings with named parameters. It works similarly to the built-in format! macro but allows for named parameters, and it safely ignores any extra parameters that are not used in the format string.
use safe_format::safe_format;
fn main() {
let name = "Allen";
let age = 19;
let pattern = "Greeting from {name}";
let greeting = safe_format!(pattern, name = name, age = age);
println!("{}", greeting); // Output: Greeting from Allen
}
First, add the safe_format_macro crate as a dependency in your Cargo.toml:
[dependencies]
safe_format = 0.1