1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use super::Expr;
/// Returns `true` if any item in a collection evaluates to `true`.
///
/// Evaluates its inner expression and returns `true` if at least one item is
/// truthy. Returns `false` for an empty collection.
///
/// # Examples
///
/// ```text
/// any([true, false, false]) // returns `true`
/// any([false, false]) // returns `false`
/// any([]) // returns `false`
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct ExprAny {
/// Expression that evaluates to a list.
pub expr: Box<Expr>,
}
impl Expr {
/// Creates an `Any` expression that returns true if any item in the list evaluates to true.
///
/// Returns false if the list is empty (matching Rust's `[].iter().any()` semantics).
pub fn any(expr: impl Into<Expr>) -> Self {
ExprAny {
expr: Box::new(expr.into()),
}
.into()
}
/// Returns true if this is an `Any` expression
pub fn is_any(&self) -> bool {
matches!(self, Self::Any(_))
}
}
impl From<ExprAny> for Expr {
fn from(value: ExprAny) -> Self {
Self::Any(value)
}
}