Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
/ ruuls-rs Public archive
forked from bsundsrud/ruuls-rs

Simple rules engine/constraint checker in Rust

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

GopherJ/ruuls-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ruuls-rs

Installation

Add this package to Cargo.toml of your project. (Check https://crates.io/crates/json-rules-engine for right version)

[dependencies]
json-rules-engine = { version = "0.2.0" }
tokio = { version = "0.3.3", features = ["macros"] }
serde_json = { version = "*" }

Features

  • Built in operators
  • Full support for ALL and ANY boolean operators, including recursive nesting
  • Type Safe
  • Lightweight
  • Load rules from json
  • HTTP post to callback url
  • Built in Moustache render

Get started

use ruuls::{Engine, Rule};
use serde_json::json;

#[tokio::main]
async main() -> anyhow::Result<()> {
    let rule_json = json!({
        "conditions": {
            "and": [
                {
                    "field": "name",
                    "operator": "string_equals",
                    "value": "Cheng JIANG"
                },
                {
                    "field": "age",
                    "operator": "int_in_range",
                    "value": [20, 25] 
                },
                {
                    "field": "action",
                    "operator": "string_equals",
                    "value": "coding in rust"
                }
            ]
        },
        "event": {
            "type": "post_to_callback_url",
            "params": {
                "callback_url": "http://example.com/people/conding_in_rust"
                "type": "info",
                "title": "Another person is coding in rust",
                "message": "Name: {{ name }}, Age: {{ age }}, Action: {{ action }},"
            }
        }
    });

    let rule: Rule = serde_json::from_str(serde_json::to_string(&rules_json).unwrap()).unwrap();

    let mut engine = Engine::new();
    engine.add_rule(rule);

    let facts = json!({
        "name": "Cheng JIANG",
        "age": 24,
        "action": "coding in rust",
    });

    let rule_results = engine.run(&facts).await?;

    println!("{:?}", rule_results);
}

About

Simple rules engine/constraint checker in Rust

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%