pub struct Template { /* private fields */ }
Expand description
The main type to represent the HCL template sub-languange.
A template behaves like an expression that always returns a string value. The different elements of the template are evaluated and combined into a single string to return.
See the module level
documentation for usage examples.
Implementations§
Source§impl Template
impl Template
Sourcepub fn from_expr(expr: &TemplateExpr) -> Result<Self>
pub fn from_expr(expr: &TemplateExpr) -> Result<Self>
Expands a raw template expression to a template.
§Errors
Returns an error if the parsing of raw string templates fails or if the template expression contains string literals with invalid escape sequences.
Sourcepub fn elements_mut(&mut self) -> &mut [Element]
pub fn elements_mut(&mut self) -> &mut [Element]
Returns a mutable reference to the template elements.
Source§impl Template
impl Template
Sourcepub fn add_element<T>(self, element: T) -> Template
pub fn add_element<T>(self, element: T) -> Template
Adds a template element (literal, interpolation or directive) to the template.
Sourcepub fn add_literal<T>(self, literal: T) -> Template
pub fn add_literal<T>(self, literal: T) -> Template
Adds a literal to the template.
Sourcepub fn add_interpolation<T>(self, interpolation: T) -> Templatewhere
T: Into<Interpolation>,
pub fn add_interpolation<T>(self, interpolation: T) -> Templatewhere
T: Into<Interpolation>,
Adds an interpolation to the template.
Sourcepub fn add_directive<T>(self, directive: T) -> Template
pub fn add_directive<T>(self, directive: T) -> Template
Adds a directive to the template.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Template
impl<'de> Deserialize<'de> for Template
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Evaluate for Template
impl Evaluate for Template
Source§fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>
fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>
Recursively evaluates all HCL templates and expressions in the implementing type using the
variables and functions declared in the
Context
. Read moreSource§fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>
fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors>
Recursively tries to evaluate all nested expressions in place. Read more
Source§impl Format for Template
impl Format for Template
Source§fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
fn format<W>(&self, fmt: &mut Formatter<'_, W>) -> Result<()>where
W: Write,
Formats a HCL structure using a formatter and writes the result to the provided writer. Read more
Source§impl<T> FromIterator<T> for Template
impl<T> FromIterator<T> for Template
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Creates a value from an iterator. Read more
impl Eq for Template
impl StructuralPartialEq for Template
Auto Trait Implementations§
impl Freeze for Template
impl RefUnwindSafe for Template
impl Send for Template
impl Sync for Template
impl Unpin for Template
impl UnwindSafe for Template
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.