toasty_core/stmt/
expr_is_variant.rs

1use crate::schema::app::VariantId;
2
3use super::Expr;
4
5/// Tests whether an expression evaluates to a specific enum variant.
6///
7/// This is an application-level check that abstracts over the storage format
8/// (unit enums stored as bare I64 vs data-carrying enums stored as Records).
9/// The lowerer translates this into the appropriate DB-level comparison.
10#[derive(Debug, Clone, PartialEq)]
11pub struct ExprIsVariant {
12    /// Expression evaluating to an enum value.
13    pub expr: Box<Expr>,
14    /// Identifies the variant to check against.
15    pub variant: VariantId,
16}
17
18impl Expr {
19    pub fn is_variant(expr: impl Into<Self>, variant: VariantId) -> Self {
20        ExprIsVariant {
21            expr: Box::new(expr.into()),
22            variant,
23        }
24        .into()
25    }
26}
27
28impl From<ExprIsVariant> for Expr {
29    fn from(value: ExprIsVariant) -> Self {
30        Self::IsVariant(value)
31    }
32}