1 个稳定版本

1.0.0 2024年7月23日

#141模板引擎

Download history 159/week @ 2024-07-21 17/week @ 2024-07-28 3/week @ 2024-08-04

179 每月下载量
用于 6 crates

Apache-2.0

7KB

后期格式化

这个crate提供了一个简单的方法来在运行时字符串中格式化参数,带有运行时参数名称。

这是使用复杂模板引擎的替代方案。

示例

use hydroperfox_lateformat::LateFormat;
use maplit::hashmap;

let user_string: String = "some user string: {id}".into();
assert_eq!(
    "some user string: x",
    user_string.hydroperfox_lateformat(hashmap!{"id".into() => "x".into()})
);

let user_string: String = r#"some user string: {"id"}"#.into();
assert_eq!(
    "some user string: id",
    user_string.hydroperfox_lateformat(hashmap!{"id".into() => "x".into()})
);

let user_string: String = r#"some user string: {  "id"  }"#.into();
assert_eq!(
    "some user string: id",
    user_string.hydroperfox_lateformat(hashmap!{"id".into() => "x".into()})
);

let user_string: String = "some user string: {id}".into();
assert_eq!(
    "some user string: None",
    user_string.hydroperfox_lateformat(hashmap!{})
);

依赖项

~2.4–4MB
~70K SLoC