[][src]Crate json_rules_engine

Simple rules engine that represents requirements as a tree, with each node having one or more requirements in order to be "Met".

A tree of rules is constructed, and then the .check_json() method is called. json is a nested field: value that will be given to each node in the tree for testing.

Status output can be either Met, NotMet, or Unknown if the tested field is not present in the json.

To construct a tree, see the following methods.

Example

extern crate json_rules_engine;
use serde_json::json;

let tree = json_rules_engine::and(vec![
    json_rules_engine::string_equals("name", "John Doe"),
    json_rules_engine::or(vec![
        json_rules_engine::int_equals("fav_number", 5),
        json_rules_engine::int_in_range("thinking_of", 5, 10)
    ])
]);
let mut facts = json!({
    "name": "John Doe",
    "fav_number": 5
});
let result = tree.check_value(&facts);
println!("{:?}", result);
assert!(result.status == json_rules_engine::Status::Met);
// result = ConditionResult { name: "And", status: Met, children: [ConditionResult { name: "Name is John Doe", status: Met, children: [] }, ConditionResult { name: "Or", status: Met, children: [ConditionResult { name: "Favorite number is 5", status: Met, children: [] }, ConditionResult { name: "Thinking of a number between 5 and 10", status: Unknown, children: [] }] }] }

This creates a tree like the following:

                             +---------+
                             |   AND   |
                             +---------+
          _____________________/\_______________
         |                                      |
         V                                      V
+-------------------+                       +--------+
| Name is John Doe  |                       |   OR   |
+-------------------+                       +--------+
| field: "name"     |             ______________/\___________
| value: "John Doe" |            |                           |
+-------------------+            V                           V
                      +----------------------+  +-------------------------+
                      | Favorite number is 5 |  | Number between 5 and 10 |
                      +----------------------+  +-------------------------+
                      | field: "fav_number"  |  | field: "thinking_of"    |
                      | value: 5             |  | start: 5                |
                      +----------------------+  | end: 10                 |
                                                +-------------------------+

Structs

ConditionResult

Result of checking a rules tree.

Engine
EventParams
Rule
RuleResult

Enums

Condition

Representation of a node in the rules tree

Constraint
Error
Event
Status

The status of a rule check

Functions

and

Creates a Rule where all child Rules must be Met

at_least

Creates a Rule where n child Rules must be Met

bool_equals

Creates a rule for boolean comparison.

float_contains
float_does_not_contain
float_equals

Creates a rule for float comparison.

float_greater_than
float_greater_than_inclusive
float_in
float_in_range
float_less_than
float_less_than_inclusive
float_not_equals
float_not_in
float_not_in_range
int_contains
int_does_not_contain
int_equals

Creates a rule for int comparison.

int_greater_than
int_greater_than_inclusive
int_in
int_in_range
int_less_than
int_less_than_inclusive
int_not_equals
int_not_in
int_not_in_range
or

Creates a Rule where any child Rule must be Met

string_contains
string_does_not_contains
string_equals

Creates a rule for string comparison

string_in
string_not_equals
string_not_in

Type Definitions

Result