Skip to main content

glaredb_core/expr/
is_expr.rs

1use std::fmt;
2
3use super::Expression;
4use crate::explain::context_display::{ContextDisplay, ContextDisplayMode, ContextDisplayWrapper};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum IsOperator {
8    IsTrue,
9    IsFalse,
10    IsNull,
11    IsNotNull,
12}
13
14impl fmt::Display for IsOperator {
15    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16        match self {
17            Self::IsTrue => write!(f, "IS TRUE"),
18            Self::IsFalse => write!(f, "IS FALSE"),
19            Self::IsNull => write!(f, "IS NULL"),
20            Self::IsNotNull => write!(f, "IS NOT NULL"),
21        }
22    }
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26pub struct IsExpr {
27    pub op: IsOperator,
28    pub input: Box<Expression>,
29}
30
31impl ContextDisplay for IsExpr {
32    fn fmt_using_context(
33        &self,
34        mode: ContextDisplayMode,
35        f: &mut fmt::Formatter<'_>,
36    ) -> fmt::Result {
37        write!(
38            f,
39            "{} {}",
40            ContextDisplayWrapper::with_mode(self.input.as_ref(), mode),
41            self.op
42        )
43    }
44}