use crate::expr::Expr;
use crate::expr::node::{CmpOp, ExprNode};
impl<T> Expr<T> {
fn cmp<R>(self, op: CmpOp, rhs: R) -> Expr<bool>
where
R: Into<Expr<T>>,
{
let rhs = rhs.into();
Expr::from_node(ExprNode::Cmp {
op,
lhs: Box::new(self.node),
rhs: Box::new(rhs.node),
})
}
pub fn eq<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::Eq, rhs)
}
pub fn neq<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::Neq, rhs)
}
pub fn gt<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::Gt, rhs)
}
pub fn gte<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::Gte, rhs)
}
pub fn lt<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::Lt, rhs)
}
pub fn lte<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::Lte, rhs)
}
pub fn is_distinct_from<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::IsDistinctFrom, rhs)
}
pub fn is_not_distinct_from<R: Into<Expr<T>>>(self, rhs: R) -> Expr<bool> {
self.cmp(CmpOp::IsNotDistinctFrom, rhs)
}
}