Crate rets_expression

Source
Expand description

An implementation of RCP 19 (RETS Validation Expressions) from the RESO Transport group.

§Example

use rets_expression::{Expression, Engine, EvaluateContext};
use serde_json::json;

// Parse an expression
let expression = "MlsStatus .IN. ('Active', 'Pending') .AND. (ListPrice >= 1 .OR. LAST MlsStatus = 'Incomplete')"
    .parse::<Expression>()
    .unwrap();

// Create the property data to run the expression against
let value = json!({
    "MlsStatus": "Active",
    "ListPrice": 1000000
});
// Create the previous property data to run the expression against (for when the expression
// includes references to previous data, like `LAST FieldName`)
let previous_value = json!({
    "MlsStatus": "Incomplete",
    "ListPrice": 0
});

// Create a default engine and a context in which to evaluate the expression
let engine = Engine::default();
let context = EvaluateContext::new(&engine, &value).with_previous(&previous_value);

// Evaluate the expression!
let value = expression.apply(context).unwrap();
assert_eq!(value.into_owned(), json!(true));

Modules§

function
Functions that can be used during the evaluation of an Expression.

Structs§

AndNode
A node representing the logical conjunction of two or more expressions
Engine
Global context for how to evaluate an expression
EvaluateContext
The information required to evaluate an expression
FieldNode
A node representing a reference to a field
FunctionNode
A node representing a function call
IifNode
A node representing the special IIF conditional syntax
LastFieldNode
A node representing a reference to a field from the previous value
ListNode
A node representing a list of items
LiteralNode
A node representing a literal value
NotNode
A node representing the logical negation of an expression
OpNode
A node representing a binary operation
OrNode
A node representing the logical disjunction of two or more expressions

Enums§

Error
An error that occured while evaluating an expression
Expression
An expression that can be inspected or evaluated
ExpressionOp
A binary operation in an OpNode

Traits§

Expressions
A trait that represents a list of expressions that can be used when creating nodes like AndNode or FunctionNode.
Visitor
Visit nodes in the Expression