Struct filter_ast::Tree [−][src]
pub struct Tree<T> { /* fields omitted */ }
Expand description
A compound node in a filter expression, consisting of a logical operator and a set of child expressions.
Implementations
Create an instance by collecting the rules from an iterator.
Example
let rules = vec![
Clause::new("name", "=", "jim"),
Clause::new("age", ">", "10")
];
let tree = Tree::from_iter(
Logic::And,
rules.into_iter().filter(|f| *f.field() != "age")
);
assert_eq!(1, tree.rules().len());
Create a new tree by applying a transform to all its rules.
Example
let tree = Tree::new(Logic::Or, vec![1, 2]);
let tree2 = tree.map(|x| x * 10);
assert_eq!(Tree::new(Logic::Or, vec![10, 20]), tree2);
Create a new tree by applying a fallible transform to all its rules. The function will return the first error it encounters.
Example
let tree = Tree::new(Logic::Or, vec![1, 2]);
let tree2 = tree.try_map(|x| {
if x % 2 == 0 {
Ok(x * 10)
} else {
Err(format!("Odd number: {}", x))
}
});
assert_eq!("Odd number: 1", &tree2.unwrap_err());
Trait Implementations
Auto Trait Implementations
impl<T> RefUnwindSafe for Tree<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Tree<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more