Enum filter_ast::Expr[][src]

pub enum Expr<F, P, O> {
    Tree(Tree<Expr<F, P, O>>),
    Clause(Clause<F, P, O>),
}
Expand description

A filter expression.

Filter expressions are an abstract representation of a function (val: T) -> bool.

Variants

Tree(Tree<Expr<F, P, O>>)

A sub-tree in the filter expression.

Tuple Fields of Tree

0: Tree<Expr<F, P, O>>
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.

Visit all clauses in depth-first order.

For more advanced visiting, see visit::Visit.

Trait Implementations

The resulting type after applying the & operator.

Performs the & operation. Read more

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.

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

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.

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Create a new expression representing the inverse of the provided expression.

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.