Enum filter_ast::Expr [−][src]
Expand description
A filter expression.
Filter expressions are an abstract representation of a function (val: T) -> bool
.
Variants
A sub-tree in the filter expression.
Clause(Clause<F, P, O>)
A leaf node in the filter expression.
Tuple Fields of Clause
0: Clause<F, P, O>
Implementations
Create a new clause wrapped in an Expr
.
Apply a mapping function to a reference to each clause in the expression, creating a new expression without consuming the original.
Apply a mapping function to each clause in the expression, creating a new expression.
The mapping function is allowed to return a new tree; this enables expansion of one clause into a nested sub-tree.
For a non-consuming version of this function, see Expr::map_ref
.
Apply a fallible mapping function to each clause in the expression, returning a new expression or the first error encountered. The input expression is not consumed.
This function enables fail-fast validation and adaptation of an expression.
A major use-case for try_map_ref
is schema validation: F
, P
, and O
each represent the union of possible
values in their respective positions but not all permutations are valid: A field called last_seen
might
not accept an IpAddr
operand.
The other main use-case for try_map_ref
is secondary parsing. If two operand types both serialize to strings,
then deserialization cannot immediately choose the right operand type. Guessing wrong could introduce strange
errors; it would be bad if a caller could break filtering by choosing a resource name that looked like an IP
address. In that scenario, deserialization would read the field and operator into their semantic types, while
preserving the operand as seen on the wire. Then try_map_ref
would be used to finish parsing, with the operand
interpretation being chosen based on the field and operator.
Apply a fallible mapping function to each clause in the expression, returning a new expression or the first error encountered.
This function enables fail-fast validation and adaptation of an expression.
A major use-case for try_map
is schema validation: F
, P
, and O
each represent the union of possible
values in their respective positions but not all permutations are valid: A field called last_seen
might
not accept an IpAddr
operand.
The other main use-case for try_map
is secondary parsing. If two operand types both serialize to strings,
then deserialization cannot immediately choose the right operand type. Guessing wrong could introduce strange
errors; it would be bad if a caller could break filtering by choosing a resource name that looked like an IP
address. In that scenario, deserialization would read the field and operator into their semantic types, while
preserving the operand as seen on the wire. Then try_map
would be used to finish parsing, with the operand
interpretation being chosen based on the field and operator.
For a non-consuming version of this function, see Expr::try_map_ref
.
Trait Implementations
Create a new expression representing the intersection of the provided expressions.
Usage
let a = Expr::new_clause("field", "=", "v1");
let b = Expr::new_clause("other", "=", "a");
let c = a & b;
let c_tree = c.as_tree().unwrap();
assert_eq!(c_tree.operator(), Logic::And);
assert_eq!(c_tree.rules()[0].as_clause().unwrap().field(), &"field");
assert_eq!(c_tree.rules()[1].as_clause().unwrap().field(), &"other");
Tree Simplification
This operation will try to avoid increasing tree depth by merging rules from input tree expressions
whose operator is Logic::And
. For example, (a & b) & (c & d & e)
will produce a & b & c & d & e
.
Create a new expression representing the union of the provided expressions.
Usage
let a = Expr::new_clause("field", "=", "v1");
let b = Expr::new_clause("other", "=", "a");
let c = a | b;
let c_tree = c.as_tree().unwrap();
assert_eq!(c_tree.operator(), Logic::Or);
assert_eq!(c_tree.rules()[0].as_clause().unwrap().field(), &"field");
assert_eq!(c_tree.rules()[1].as_clause().unwrap().field(), &"other");
Tree Simplification
This operation will try to avoid increasing tree depth by merging rules from input tree expressions
whose operator is Logic::And
. For example, (a | b) | (c | d | e)
will produce a | b | c | d | e
.
Auto Trait Implementations
impl<F, P, O> RefUnwindSafe for Expr<F, P, O> where
F: RefUnwindSafe,
O: RefUnwindSafe,
P: RefUnwindSafe,
impl<F, P, O> UnwindSafe for Expr<F, P, O> where
F: UnwindSafe,
O: UnwindSafe,
P: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more