pub trait LateFormat {
// Required method
fn late_format(&self, arguments: HashMap<String, String>) -> String;
}Expand description
The LateFormat trait allows substituting string parameters
of arbitrary name that is computed at runtime.
LateFormat is implemented for the String and &str types by default.
The substitution syntax accepts curly braces forms:
{param_name} # parameter to replace
{"escaped"} # escaped sequenceSyntax description:
- Whitespace is allowed around the parameter name or escaped form, such as
{ "foo" }versus{"foo"}. {param_name}expands to either an argument given in the map (whose key string isparam_name) or the stringNoneif not present. The parameter name may contain any of the following characters:
A-Z a-z 0-9 . - _ ${"escaped"}expands to the stringescaped. It is often used for escaping the curly braces.
§Example
use late_format::LateFormat;
use maplit::hashmap;
let user_string: String = "some user string: {id}".into();
assert_eq!("some user string: x", user_string.late_format(hashmap!{"id".into() => "x".into()}));
// if a string contains curly braces, they must be escaped.
let escaped: String = r#"{"{"}"#.into();