1 stable release

new 1.0.0 Feb 19, 2025

#1 in #late


Used in 2 crates (via mxmlextrema-as3parser)

Apache-2.0

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 realhydroper_lateformat::LateFormat;
use maplit::hashmap;

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

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

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

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

Dependencies

~2.3–4MB
~69K SLoC