Skip to main content

toasty_core/stmt/
expr_between.rs

1use super::Expr;
2
3/// Tests whether a value lies within an inclusive range.
4///
5/// Returns `true` if `low <= expr <= high`.
6///
7/// # Examples
8///
9/// ```text
10/// between(age, 18, 65)  // returns `true` if 18 <= age <= 65
11/// ```
12#[derive(Debug, Clone, PartialEq)]
13pub struct ExprBetween {
14    /// The value being tested.
15    pub expr: Box<Expr>,
16    /// Inclusive lower bound.
17    pub low: Box<Expr>,
18    /// Inclusive upper bound.
19    pub high: Box<Expr>,
20}
21
22impl Expr {
23    /// Creates a `BETWEEN` expression: `expr BETWEEN low AND high` (inclusive).
24    pub fn between(expr: impl Into<Self>, low: impl Into<Self>, high: impl Into<Self>) -> Self {
25        ExprBetween {
26            expr: Box::new(expr.into()),
27            low: Box::new(low.into()),
28            high: Box::new(high.into()),
29        }
30        .into()
31    }
32}
33
34impl From<ExprBetween> for Expr {
35    fn from(value: ExprBetween) -> Self {
36        Self::Between(value)
37    }
38}