toasty_core/stmt/
expr_not.rs

1use super::Expr;
2
3/// Negates a boolean expression.
4///
5/// Returns `true` if the inner expression evaluates to `false`, and vice versa.
6/// Returns `NULL` if the inner expression evaluates to `NULL`.
7///
8/// # Examples
9///
10/// ```text
11/// not(true)   // returns `false`
12/// not(false)  // returns `true`
13/// not(null)   // returns `null`
14/// ```
15#[derive(Debug, Clone, PartialEq)]
16pub struct ExprNot {
17    /// The expression to negate.
18    pub expr: Box<Expr>,
19}
20
21impl Expr {
22    /// Creates a `Not` expression that negates the given expression.
23    pub fn not(expr: impl Into<Self>) -> Self {
24        ExprNot {
25            expr: Box::new(expr.into()),
26        }
27        .into()
28    }
29
30    /// Returns true if this is a `Not` expression.
31    pub fn is_not(&self) -> bool {
32        matches!(self, Self::Not(_))
33    }
34}
35
36impl From<ExprNot> for Expr {
37    fn from(value: ExprNot) -> Self {
38        Self::Not(value)
39    }
40}