pub struct TemplateBuf { /* private fields */ }Expand description
A parsed string template that owns the source string.
You can parse the template once and call Self::expand() multiple times.
This is generally more efficient than calling substitute() multiple times on the same string.
This template owns the source string.
If you do not need ownership, you can also use Template to borrow it instead.
Depending on your application, that could prevent creating an unnecessary copy of the source data.
If you have a byte slice or vector instead of a string,
you can use ByteTemplate or ByteTemplateBuf.
Implementations§
Source§impl TemplateBuf
impl TemplateBuf
Sourcepub fn from_string(source: String) -> Result<Self, ParseError>
pub fn from_string(source: String) -> Result<Self, ParseError>
Parse a template from a string.
This takes ownership of the string.
The source is can contain variables to be substituted later,
when you call Self::expand().
Variables have the form $NAME, ${NAME} or ${NAME:default}.
A variable name can only consist of ASCII letters, digits and underscores.
They are allowed to start with numbers.
You can escape dollar signs, backslashes, colons and braces with a backslash.
Sourcepub fn into_source(self) -> String
pub fn into_source(self) -> String
Consume the template to get the original source string.
Sourcepub fn as_template<'a>(&'a self) -> &'a Template<'a>
pub fn as_template<'a>(&'a self) -> &'a Template<'a>
Borrow the template.