Expand description
String templates with ${name} placeholders that have to be resolved
before use.
ExpandStr wraps a template string and refuses to be implicitly
coerced to a &str: it does not implement Display, AsRef<str>,
or Deref<Target = str>. Callers go through
expand_to_string or
write_expanded with an ExpandLookup,
and the missing trait impls mean the compiler complains the moment a
raw template leaks into a println!, a path, or a shell command.
Placeholders are exactly ${name} — no other syntax, no escape
sequence. An unresolved placeholder is an error; so is an unterminated
${. The lookup side is pluggable: implement ExpandLookup yourself,
reach for the HashMap / BTreeMap / IndexMap impls that ship
with the crate, or chain several with [&dyn ExpandLookup; N] for an
ordered fallback search.
§Example
use std::collections::HashMap;
use zenops_expand::ExpandStr;
let t = ExpandStr::new_static("hello, ${name}!");
let mut lookup = HashMap::new();
lookup.insert("name", "world");
assert_eq!(t.expand_to_string(&lookup).unwrap(), "hello, world!");§Features
indexmap—ExpandLookupimpl for [indexmap::IndexMap].
Structs§
- Expand
Str - A template string with
${name}placeholders, awaiting expansion.
Enums§
- Expand
Error - Error returned from expanding an
ExpandStr. - Expand
Lookup Error - Error returned from
ExpandLookup::write_value.
Traits§
- Expand
Lookup - Resolves
${name}placeholders to their values.