toasty_core/stmt/expr_is_null.rs
1use super::Expr;
2
3/// Tests whether an expression is null.
4///
5/// Returns `true` if the expression evaluates to null.
6///
7/// # Examples
8///
9/// ```text
10/// is_null(x) // returns `true` if x is null
11/// is_not_null(x) // returns `true` if x is not null
12/// ```
13#[derive(Debug, Clone, PartialEq)]
14pub struct ExprIsNull {
15 /// The expression to check for null.
16 pub expr: Box<Expr>,
17}
18
19impl Expr {
20 pub fn is_null(expr: impl Into<Self>) -> Self {
21 ExprIsNull {
22 expr: Box::new(expr.into()),
23 }
24 .into()
25 }
26
27 pub fn is_not_null(expr: impl Into<Self>) -> Self {
28 Self::not(Self::is_null(expr))
29 }
30}
31
32impl From<ExprIsNull> for Expr {
33 fn from(value: ExprIsNull) -> Self {
34 Self::IsNull(value)
35 }
36}