evalx
Evalx is a powerful expression evaluator.
This crate is a maintained fork and further development of the original eval by fengcen. The continuation mainly includes bugfixes and updating the Rust edition to 2021, while keeping the public API compatible.
Documentation
Features
Supported operators: ! != "" '' () [] , > < >= <= ==
+ - * / % && || n..m.
Built-in functions: min() max() len() is_empty() array().
Where can evalx be used?
- Template engine
- ...
Usage
Add dependency to Cargo.toml
[]
= "^0.5"
In your code:
use ;
Examples
You can do mathematical calculations with supported operators:
use ;
assert_eq!;
assert_eq!;
assert_eq!;
You can eval with context:
use ;
assert_eq!;
You can access data like javascript by using . and []. [] supports expression.
use ;
use HashMap;
let mut object = new;
object.insert;
assert_eq!;
You can eval with function:
use ;
assert_eq!;
You can create an array with array():
use ;
assert_eq!;
You can create an integer array with n..m:
use ;
assert_eq!;
Linting (Clippy)
This repository is set up with Clippy for linting.
- Install Clippy (if needed):
rustup component add clippy
- Run Clippy normally:
cargo clippy
- Strict mode (treat all warnings as errors):
cargo clippy-strict
- Pedantic mode (more lints, as warnings):
cargo clippy-pedantic
- CI: Clippy runs in GitHub Actions (see
.github/workflows/ci.yml).
License
evalx is primarily distributed under the terms of the MIT license. See LICENSE for details.