pub struct Interpolation { /* private fields */ }Expand description
The main entrypoint for this crate.
Created with Interpolation::new, this represents
a template that can be supplied variables to render.
Implementations§
Source§impl Interpolation
impl Interpolation
Sourcepub fn new(input: impl AsRef<str>) -> Result<Self, ParseError>
pub fn new(input: impl AsRef<str>) -> Result<Self, ParseError>
Create a new Interpolation.
§Errors
This function usually errors when there is a syntax error in the interpolation compiler, e.g. an unclosed identifier or an invalid escape.
Sourcepub fn render(&self, args: &HashMap<Cow<'_, str>, Cow<'_, str>>) -> String
pub fn render(&self, args: &HashMap<Cow<'_, str>, Cow<'_, str>>) -> String
Renders this template, using the args hashmap to fetch
interpolation values from. Said values must be strings.
If an interpolation value is not found, it is replaced with an empty string.
Sourcepub fn try_render(
&self,
args: &HashMap<Cow<'_, str>, Cow<'_, str>>,
) -> Result<String, RenderError<'_>>
pub fn try_render( &self, args: &HashMap<Cow<'_, str>, Cow<'_, str>>, ) -> Result<String, RenderError<'_>>
Renders this template, using the args hashmap to fetch
interpolation values from. Said values must be strings.
§Errors
If an interpolation value is not found, it is added to the RenderError.
Sourcepub fn variables_used(&self) -> impl Iterator<Item = &str>
pub fn variables_used(&self) -> impl Iterator<Item = &str>
Returns an iterator over all variables used in this interpolation. Useful if you have a non hashmap item you wish to get items from.
pub fn input_value(&self) -> String
Trait Implementations§
Source§impl Clone for Interpolation
impl Clone for Interpolation
Source§fn clone(&self) -> Interpolation
fn clone(&self) -> Interpolation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more