Skip to main content

Crate zenops_expand

Crate zenops_expand 

Source
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

Structs§

ExpandStr
A template string with ${name} placeholders, awaiting expansion.

Enums§

ExpandError
Error returned from expanding an ExpandStr.
ExpandLookupError
Error returned from ExpandLookup::write_value.

Traits§

ExpandLookup
Resolves ${name} placeholders to their values.