hcl/expr/conditional.rs
1use super::Expression;
2use serde::Deserialize;
3
4/// The conditional operator allows selecting from one of two expressions based on the outcome of a
5/// boolean expression.
6#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
7pub struct Conditional {
8 /// A condition expression that evaluates to a boolean value.
9 pub cond_expr: Expression,
10 /// The expression returned by the conditional if the condition evaluates to `true`.
11 pub true_expr: Expression,
12 /// The expression returned by the conditional if the condition evaluates to `false`.
13 pub false_expr: Expression,
14}
15
16impl Conditional {
17 /// Creates a new `Conditional` from a condition and two expressions for the branches of the
18 /// conditional.
19 pub fn new<C, T, F>(cond_expr: C, true_expr: T, false_expr: F) -> Conditional
20 where
21 C: Into<Expression>,
22 T: Into<Expression>,
23 F: Into<Expression>,
24 {
25 Conditional {
26 cond_expr: cond_expr.into(),
27 true_expr: true_expr.into(),
28 false_expr: false_expr.into(),
29 }
30 }
31}