Enum rapidquery::Expression
source · [−]pub enum Expression {
Tag {
tag: String,
},
KeyValue {
key: String,
value: String,
},
HasKey {
key: String,
},
Parent {
parent: String,
},
And {
and: (Box<Expression>, Box<Expression>),
},
Or {
or: (Box<Expression>, Box<Expression>),
},
Not {
not: Box<Expression>,
},
Empty,
}
Expand description
A parsed (or manually constructed) query expression.
An expression can be arbitrarily nested.
Variants
Tag
Fields
tag: String
Tag expression.
Evaluates to resolver items where the tag is present.
KeyValue
Key/Value expression.
Evaluates to resolver items where the given key/value pair is present.
HasKey
Fields
key: String
HasKey expression.
Evaluates to resolver items where the given key is present (in any key/value pair).
Parent
Fields
parent: String
Parent expression.
Evaluates to resolver items having the provided value as a parent.
And
Fields
and: (Box<Expression>, Box<Expression>)
And expression.
Evaluates to the intersection of its two sub-expressions.
Or
Fields
or: (Box<Expression>, Box<Expression>)
Or expression. Evaluates to the union of its two sub-expressions.
Not
Fields
not: Box<Expression>
Not expression. Evaluates to the negation of its sub-expression.
Empty
Empty expression. Evaluates to all items resolvable by the resolver.
Implementations
Parse an expression from a string.
Returns an error if the provided string could not be parsed.
Examples
use rapidquery::Expression;
let expression = "a && b";
match Expression::parse(expression) {
Ok(expr) => println!("Got expression: {:?}", expr),
Err(e) => panic!("failed to parse")
}
pub fn evaluate<R, V, E>(&self, resolver: &R) -> Result<V, E> where
V: BitAndAssign + BitOrAssign + Not<Output = V> + Span + Display,
R: Resolver<V, Error = E>,
pub fn evaluate<R, V, E>(&self, resolver: &R) -> Result<V, E> where
V: BitAndAssign + BitOrAssign + Not<Output = V> + Span + Display,
R: Resolver<V, Error = E>,
Evaluate an expression using a resolver.
The resolver is tasked with resolving the sets corresponding to the various sub-expressions kinds (tags, key/value pairs, etc.). From there, the evaluator will recursively compute the query, calling the resolver when appropriate.
Examples
use rapidquery::{Expression, Resolver};
let resolver: Box<dyn Resolver<bool, Error = std::io::Error>> = {
unimplemented!()
};
let expr = Expression::Empty;;
let evaluation: bool = expr.evaluate(&resolver)?;
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more