pub fn apply(
parameterized: impl AsRef<str>,
arguments: &Map,
process: Option<fn(arg: &Box<dyn Any>) -> String>,
) -> StringExpand description
Applies arguments to a paramaterized string. The function supports an optional processor function to manipulate given arguments.
If no processor function is specified, the arguments are forced to be either
of the type String or &'static str.
If a parameter is missing from the arguments map, it is replaced by "None".
§Syntax
The following sequences are affected by the function:
$parametername(cannot contain hyphens and underscores)$<parameter-name>(can contain hyphens and underscores)$$(translates to a single dollar sign)
§Example
// forces arguments to either `String` or `&'static str`.
let applied = template_string::apply("$<foo-qux>", &template_string::map! { "foo-qux" => "Fq" }, None);
assert_eq!(applied, "Fq".to_owned());
// uses a processor.
let applied = template_string::apply("$<foo-qux>", &template_string::map! { "foo-qux" => "Fq" }, Some(|v| (*v.downcast_ref::<&'static str>().unwrap()).to_owned()));
assert_eq!(applied, "Fq".to_owned());
// lacking parameter.
let applied = template_string::apply("$<foo-qux>", &template_string::map! {}, None);
assert_eq!(applied, "None".to_owned());