2 stable releases
new 1.0.1 | Jul 5, 2025 |
---|---|
1.0.0 | May 17, 2025 |
#253 in Template engine
93 downloads per month
8KB
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 hydroperx_lateformat::LateFormat;
use maplit::hashmap;
let user_string: String = "some user string: {id}".into();
assert_eq!(
"some user string: x",
user_string.lateformat(hashmap!{"id".into() => "x".into()})
);
let user_string: String = r#"some user string: {"id"}"#.into();
assert_eq!(
"some user string: id",
user_string.lateformat(hashmap!{"id".into() => "x".into()})
);
let user_string: String = r#"some user string: { "id" }"#.into();
assert_eq!(
"some user string: id",
user_string.lateformat(hashmap!{"id".into() => "x".into()})
);
let user_string: String = "some user string: {id}".into();
assert_eq!(
"some user string: None",
user_string.lateformat(hashmap!{})
);
Dependencies
~2.4–4MB
~69K SLoC