6个版本
0.1.5 | 2024年7月9日 |
---|---|
0.1.4 | 2024年7月9日 |
#163 在 值格式化
每月399 次下载
7KB
65 代码行
safe_format
safe_format
是一个Rust的过程宏,允许您使用命名参数安全地格式化字符串。它与内置的 format!
宏类似,但允许使用命名参数,并且安全地忽略格式字符串中未使用的任何额外参数。
功能
- 字符串格式化的命名参数。
- 忽略格式字符串中未使用的额外参数。
- 简单直观的API。
使用
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
}
添加依赖项
首先,将 safe_format_macro
crate 作为依赖项添加到您的 Cargo.toml
[dependencies]
safe_format = 0.1
依赖项
~285–740KB
~18K SLoC