pub struct Template<'a>(/* private fields */);Expand description
A lazily evaluated text template with named holes for interpolating properties into.
The Template::render method can be used to format a template with Props into a string or other representation.
Template equality is based on the equality of their renderings.
Two templates can be equal if they’d render to the same outputs. That means they must have the same holes in the same positions, but their text tokens may be split differently, so long as they produce the same text.
Implementations§
Source§impl<'a> Template<'a>
impl<'a> Template<'a>
Sourcepub const fn new_ref(parts: &'a [Part<'a>]) -> Template<'a>
pub const fn new_ref(parts: &'a [Part<'a>]) -> Template<'a>
Create a template from a borrowed set of tokens.
The Template::new method should be preferred where possible.
Sourcepub const fn literal_ref(text: &'a str) -> Template<'a>
pub const fn literal_ref(text: &'a str) -> Template<'a>
Create a template from a string literal with no holes.
The Template::literal method should be preferred where possible.
Sourcepub fn as_literal(&self) -> Option<&Str<'a>>
pub fn as_literal(&self) -> Option<&Str<'a>>
Try get the value of the template as a string literal.
If the template only has a single token, and that token is text, then this method will return Some. Otherwise this method will return None.
Trait Implementations§
Source§impl<'k> Serialize for Template<'k>
Available on crate feature serde only.
impl<'k> Serialize for Template<'k>
serde only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<'k> Value for Template<'k>
Available on crate feature sval only.
impl<'k> Value for Template<'k>
sval only.Source§fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
fn stream<'sval, S>(&'sval self, stream: &mut S) -> Result<(), Error>
Stream.