Skip to main content

Criteria

Enum Criteria 

Source
#[non_exhaustive]
pub enum Criteria { Value(Value), Property(Vec<String>), Parameter(String), Unary(UnaryOp, Box<Criteria>), Binary(BinaryOp, Box<Criteria>, Box<Criteria>), Group(GroupOp, Vec<Criteria>), In(Box<Criteria>, Vec<Criteria>), Between(Box<Criteria>, Box<Criteria>, Box<Criteria>), IsNull(Box<Criteria>), Function(Function, Vec<Criteria>), Custom(String, Vec<Criteria>), Aggregate(Box<AggregateCall>), }
Expand description

A parsed expression or filter.

use ravenrs_criteria::Criteria;

let c = Criteria::parse("[Price] * [Qty] > 100 And [Active]").expect("valid");
assert_eq!(c.to_string(), "[Price] * [Qty] > 100 And [Active]");
assert_eq!(c.properties(), ["Price", "Qty", "Active"]);

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Value(Value)

A literal.

§

Property(Vec<String>)

A field path, such as Customer.Name; a leading ^ reads the parent row.

§

Parameter(String)

A parameter, ?Name.

§

Unary(UnaryOp, Box<Criteria>)

A unary operator.

§

Binary(BinaryOp, Box<Criteria>, Box<Criteria>)

A binary operator.

§

Group(GroupOp, Vec<Criteria>)

And or Or over two or more operands.

§

In(Box<Criteria>, Vec<Criteria>)

value In (a, b, c).

§

Between(Box<Criteria>, Box<Criteria>, Box<Criteria>)

value Between(low, high).

§

IsNull(Box<Criteria>)

value Is Null.

§

Function(Function, Vec<Criteria>)

A built-in function.

§

Custom(String, Vec<Criteria>)

A function resolved by name when evaluated (see crate::Environment::register).

§

Aggregate(Box<AggregateCall>)

An aggregate over the current scope, or over a nested collection.

Implementations§

Source§

impl Criteria

Source

pub fn parse(source: &str) -> Result<Criteria, ParseError>

Parses source; see the crate documentation for the syntax.

Source

pub fn assignments(source: &str) -> Result<Vec<(String, Criteria)>, ParseError>

Parses assignments, field = expression; ..., as an update sets fields: each field with the expression that gives its new value.

use ravenrs_criteria::Criteria;

let set = Criteria::assignments("state = 'done'; [finished] = Today()").unwrap();
assert_eq!(set[0].0, "state");
assert_eq!(set[1].0, "finished");
Source

pub fn property(path: &str) -> Criteria

A field.

Source

pub fn value(value: impl Into<Value>) -> Criteria

A literal.

Source

pub fn equals(self, other: Criteria) -> Criteria

self = other.

Source

pub fn and(self, other: Criteria) -> Criteria

self And other, flattening nested Ands.

Source

pub fn or(self, other: Criteria) -> Criteria

self Or other, flattening nested Ors.

Source

pub fn walk(&self, f: &mut dyn FnMut(&Criteria))

Calls f on this node and everything under it.

Source

pub fn properties(&self) -> Vec<String>

The field paths used, in order, without repeats.

Source

pub fn parameters(&self) -> Vec<String>

The parameter names used, in order, without repeats.

Source

pub fn any(&self, test: &dyn Fn(&Criteria) -> bool) -> bool

True when any node satisfies test.

Trait Implementations§

Source§

impl Clone for Criteria

Source§

fn clone(&self) -> Criteria

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Criteria

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for Criteria

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Not for Criteria

Source§

fn not(self) -> Criteria

Not self.

Source§

type Output = Criteria

The resulting type after applying the ! operator.
Source§

impl PartialEq for Criteria

Source§

fn eq(&self, other: &Criteria) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Criteria

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.