pub struct Template<'t> { /* private fields */ }
Expand description
The Template
type is the basis for most simple tasks. Parsing and
expansion are both template functions.
Implementations§
Source§impl<'t> Template<'t>
impl<'t> Template<'t>
Sourcepub fn expand(&self, values: &Values) -> Result<String, ExpandError>
pub fn expand(&self, values: &Values) -> Result<String, ExpandError>
Expands the template using the given Values
, returning a String
if expansion was successful.
§Errors
This function may fail due to internal formatting errors
(std::fmt::Write
is an abstraction which allows for underlying
failures) though this is very unlikely given String
output.
let template = Template::parse("hello/{name}!").unwrap();
let values = Values::default().add("name", Value::item("world"));
assert_eq!("hello/world!", template.expand(&values).unwrap());
Sourcepub fn parse(raw: &'t str) -> Result<Template<'t>, ParseError>
pub fn parse(raw: &'t str) -> Result<Template<'t>, ParseError>
Parses a &str
representing a potential template, and returns a new
Template
instance if valid. See RFC6570
for the grammar of a valid URI Template. uri-template-system
supports
all operators and modifiers up-to and including Level 4.
§Errors
This function may fail when the given input is not a valid URI Template
according the RFC-defined grammar. The resultant ParseError
should give useful information about where the parser failed.
let template = Template::parse("my/valid/{template}");
assert!(template.is_ok());