1 unstable release
new 0.1.0 | Feb 14, 2025 |
---|
#772 in Parser implementations
122 downloads per month
71KB
1.5K
SLoC
Power Fx interpreter for Rust
This crate provides an embedded Power Fx interpreter for Rust projects.
Getting started
Install the package.
cargo add powerfx
Status
This library is still an an alpha status. The following functions have been implemented:
- Table
- First
- Last
- Index
- Filter
- Set
- If
- And
- Or
- Not
- Abs
- Sqrt
- Left
- Mid
- Right
- Upper
- Lower
- Average
- Sum
- Min
- Max
Examples
The following example illustrates adding two constant numbers.
use powerfx::{DataValue, PowerFxEngine};
fn main() {
let engine = PowerFxEngine::new();
let result = engine.evaluate("2 + 3", None).unwrap();
assert_eq!(result, DataValue::Number(5.0));
}
This can also be done with variables.
let engine = PowerFxEngine::new();
let mut session = Session::new();
session.set_variable("a", DataValue::Number(2.0));
session.set_variable("b", DataValue::Number(3.0));
let result = engine.evaluate("a + b", Some(&mut session)).unwrap();
assert_eq!(result, DataValue::Number(5.0));
For more examples, please see the Examples Folder
Dependencies
~4–10MB
~92K SLoC