Config Expression
A flexible configuration expression evaluator that supports rule systems defined by JSON schema.
Features
- π High Performance: Implemented in Rust with zero-copy parsing
- π JSON Schema: Clear and semantically explicit JSON rule definitions
- π§ Extensible: Supports multiple operators and compound conditions
- π― Type Safe: Full Rust type system support
- β Validator: Built-in rule validity validation
- π Frontend/Backend Friendly: Easy to configure on frontend and execute on backend
Supported Operators
| Operator | Description | Example | Note |
|---|---|---|---|
equals |
Exact equals | "platform" equals "RTD" |
String comparison |
contains |
Contains | "platform" contains "RTD" |
String comparison |
prefix |
Prefix match | "platform" prefix "Hi" |
String comparison |
suffix |
Suffix match | "platform" suffix "Pro" |
String comparison |
regex |
Regex match | "version" regex "^v\\d+\\.\\d+\\.\\d+$" |
String comparison |
gt |
Greater than | "score" gt "80" |
Numeric comparison |
lt |
Less than | "age" lt "18" |
Numeric comparison |
ge |
Greater than or equal | "level" ge "5" |
Numeric comparison |
le |
Less than or equal | "temperature" le "25.5" |
Numeric comparison |
Supported Condition Types
- Simple Condition: Single field comparison
- AND Condition: All sub-conditions must be satisfied
- OR Condition: At least one sub-condition must be satisfied
- Nested Conditions: Supports arbitrary levels of condition nesting
Getting Started
Add Dependency
[]
= "0.1.1"
Basic Usage
use ;
use HashMap;
JSON Schema Structure
Basic Structure
Condition Expressions
Simple Condition
String comparison:
Numeric comparison:
AND Condition
OR Condition
Return Value Types
String Return Value
JSON Object Return Value
API Documentation
Main Types
ConfigEvaluator: Configuration expression evaluatorConfigRules: Rule set definitionCondition: Condition expressionRuleResult: Rule result (string or JSON object)Operator: Operator enumeration
Main Methods
evaluate_json(json, params): Directly evaluate from JSON stringvalidate_json(json): Validate if JSON rules are validConfigEvaluator::from_json(json): Create evaluator from JSONevaluator.evaluate(params): Evaluate parameters and return result
Run Examples
Run Tests
License
This project is dual-licensed under MIT or Apache-2.0.
A JSON-based configuration expression processor.