macro_rules! cvlr_and {
($a:expr, $b:expr) => { ... };
($a:expr, $b:expr, $c:expr) => { ... };
($a:expr, $b:expr, $c:expr, $d:expr) => { ... };
($a:expr, $b:expr, $c:expr, $d:expr, $e:expr) => { ... };
($a:expr, $b:expr, $c:expr, $d:expr, $e:expr, $f:expr) => { ... };
}Expand description
Creates a boolean expression representing the logical AND of two or more expressions.
This macro is a convenience wrapper around cvlr_and that
provides flexible syntax for combining boolean expressions. It supports both identifiers
and expressions as arguments, and can combine 2 to 6 expressions.
§Syntax
ⓘ
cvlr_and!(a, b) // Two arguments
cvlr_and!(a, b, c) // Three arguments
cvlr_and!(a, b, c, d) // Four arguments
cvlr_and!(a, b, c, d, e) // Five arguments
cvlr_and!(a, b, c, d, e, f) // Six arguments§Arguments
The macro accepts identifiers or expressions that implement CvlrFormula
with the same context type. Arguments can be:
- Identifiers (e.g.,
XPositive) - Expressions (e.g.,
cvlr_predicate! { | c : Ctx | -> { c.x > 0 } }) - Mixed (e.g.,
cvlr_and!(XPositive, cvlr_predicate! { | c : Ctx | -> { c.y > 0 } }))
§Returns
Returns a value implementing CvlrFormula that evaluates to true
only when all input expressions evaluate to true.
§Examples
ⓘ
use cvlr_spec::{cvlr_and, cvlr_predicate, CvlrFormula};
struct Counter {
value: i32,
}
// Using identifiers
cvlr_def_predicate! {
pred IsPositive(c: Counter) {
c.value > 0
}
}
cvlr_def_predicate! {
pred IsEven(c: Counter) {
c.value % 2 == 0
}
}
let ctx = Counter { value: 6 };
let expr = cvlr_and!(IsPositive, IsEven);
assert!(expr.eval(&ctx));
// Using expressions
let expr2 = cvlr_and!(
cvlr_predicate! { | c : Counter | -> { c.value > 0 } },
cvlr_predicate! { | c : Counter | -> { c.value < 100 } }
);
assert!(expr2.eval(&ctx));
// Using multiple arguments
let expr3 = cvlr_and!(
IsPositive,
IsEven,
cvlr_predicate! { | c : Counter | -> { c.value < 100 } }
);
assert!(expr3.eval(&ctx));