pub trait Evaluate: Sealed {
type Output;
// Required method
fn evaluate(&self, ctx: &Context<'_>) -> EvalResult<Self::Output>;
// Provided method
fn evaluate_in_place(&mut self, ctx: &Context<'_>) -> EvalResult<(), Errors> { ... }
}
Expand description
A trait for evaluating the HCL template and expression sub-languages.
The types implementing this trait must recursively evaluate all HCL templates and expressions in their fields.
This trait is sealed to prevent implementation outside of this crate.
Required Associated Types§
Required Methods§
Sourcefn 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
.
See the module-level documentation for usage examples.
§Errors
This function fails with an error if:
- an expression evaluates to a value that is not allowed in a given context, e.g. a string occures where a boolean value is expected.
- an operation is performed on values that it’s not applicable to.
- an undefined variable or function is encountered.
- a defined function is called with unexpected arguments.
Provided Methods§
Sourcefn 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.
This function does not stop at the first error but continues to evaluate expressions as far as it can.
The default implementation does nothing and always returns Ok(())
.
§Errors
Returns an Errors
value containing one of more Error
s if the evaluation of any
(potentially nested) expression fails.
See the errors section of evaluate
for a list of failure modes.