1 stable release
1.0.0 | Jul 23, 2024 |
---|
#204 in Template engine
45 downloads per month
Used in 6 crates
7KB
Late format
This crate provides a simple way of formatting parameters in a runtime string, with runtime parameter names.
This is an alternative to using complex template engines.
Example
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!{})
);
Dependencies
~2.5–4MB
~72K SLoC