use super::Expression;
use serde::Deserialize;
#[doc(inline)]
pub use hcl_primitives::expr::{BinaryOperator, UnaryOperator};
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
pub enum Operation {
Unary(UnaryOp),
Binary(BinaryOp),
}
impl From<UnaryOp> for Operation {
fn from(op: UnaryOp) -> Self {
Operation::Unary(op)
}
}
impl From<BinaryOp> for Operation {
fn from(op: BinaryOp) -> Self {
Operation::Binary(op)
}
}
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct UnaryOp {
pub operator: UnaryOperator,
pub expr: Expression,
}
impl UnaryOp {
pub fn new<T>(operator: UnaryOperator, expr: T) -> UnaryOp
where
T: Into<Expression>,
{
UnaryOp {
operator,
expr: expr.into(),
}
}
}
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct BinaryOp {
pub lhs_expr: Expression,
pub operator: BinaryOperator,
pub rhs_expr: Expression,
}
impl BinaryOp {
pub fn new<L, R>(lhs_expr: L, operator: BinaryOperator, rhs_expr: R) -> BinaryOp
where
L: Into<Expression>,
R: Into<Expression>,
{
BinaryOp {
lhs_expr: lhs_expr.into(),
operator,
rhs_expr: rhs_expr.into(),
}
}
}