1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! A rule engine written in rust.
//! There's also a [python fork](https://github.com/tclh123/rule).
//!
//! The rule is a json string or rust object of a list expression.
//! The expression is like `[op, arg0, arg1, ..., argn]`, the `op` is the operator,
//! and `arg0..n` is the arguments for the operator. Any argument can be another expression.
//!
//! For writing convenience, the first argument will be tried to resolve as the context parameter.
//! Or, you can just use the special `var` operator to indicate the context parameter.
//!
//! # Usage
//!
//! ```rust
//! #[macro_use]
//! extern crate rule;
//!
//! use rule::{Rule, Result};
//!
//! fn main() -> Result<()> {
//! let context = json!({"a": 1, "world": "hello"});
//!
//! // match the context with rules
//! assert!(Rule::new(json!(["=", "a", 1]))?.matches(&context)?);
//! assert!(Rule::new(json!(["=", ["var", "a"], 1]))?.matches(&context)?);
//! assert!(Rule::from_str(r#"["=", ["var", "a"], 1]"#)?.matches(&context)?);
//! assert!(Rule::from_value(["=", "world", "hello"])?.matches(&context)?);
//!
//! // rule! macro
//! assert!(rule!["=", "a", 1]?.matches(&context)?);
//!
//! // collection operators
//! assert!(rule!["in", 1, 1, 2, 3]?.matches(&json!({}))?);
//! assert!(rule!["startswith", "hello", "he"]?.matches(&json!({}))?);
//! assert!(rule!["startswith", "arr", "foo", "bar"]?.matches(&json!({"arr": ["foo", "bar", "baz"]}))?);
//! assert!(rule!["endswith", "arr", "bar", "baz"]?.matches(&json!({"arr": ["foo", "bar", "baz"]}))?);
//!
//! Ok(())
//! }
//! ```
extern crate serde_json;
pub use json;
extern crate lazy_static;
pub use Rule;
pub use ;