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