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

Fields

key: String
value: String

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

And expression.

Evaluates to the intersection of its two sub-expressions.

Or

Or expression. Evaluates to the union of its two sub-expressions.

Not

Fields

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")
}

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. 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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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)

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.

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