toasty_core/stmt/expr_starts_with.rs
1use super::Expr;
2
3/// A string prefix-match expression: `starts_with(expr, prefix)`.
4///
5/// Returns `true` if `expr` starts with `prefix`. The attribute reference
6/// is always `expr` (lhs) and the prefix value is always `prefix` (rhs).
7///
8/// # Examples
9///
10/// ```text
11/// starts_with(name, "Al") // true if name starts with "Al"
12/// ```
13#[derive(Debug, Clone, PartialEq)]
14pub struct ExprStartsWith {
15 /// The attribute to test.
16 pub expr: Box<Expr>,
17
18 /// The prefix value to match against.
19 pub prefix: Box<Expr>,
20}
21
22impl Expr {
23 /// Creates a `starts_with(expr, prefix)` expression.
24 pub fn starts_with(expr: impl Into<Self>, prefix: impl Into<Self>) -> Self {
25 ExprStartsWith {
26 expr: Box::new(expr.into()),
27 prefix: Box::new(prefix.into()),
28 }
29 .into()
30 }
31}
32
33impl From<ExprStartsWith> for Expr {
34 fn from(value: ExprStartsWith) -> Self {
35 Self::StartsWith(value)
36 }
37}