| Crates.io | oxide_eval |
| lib.rs | oxide_eval |
| version | 0.1.2 |
| created_at | 2025-05-18 15:45:30.585291+00 |
| updated_at | 2025-08-01 10:12:44.929643+00 |
| description | Oxide Eval is a simple Javascript Evaluator based on oxc. |
| homepage | |
| repository | https://github.com/respectZ/oxide_eval/ |
| max_upload_size | |
| id | 1678740 |
| size | 96,552 |
oxide_eval is a simple Javascript Evaluator built on top of oxc
use std::collections::HashMap;
use oxide_eval::{context::ContextEntry, Evaluator};
use serde_json::{Number, Value};
let mut context = HashMap::new();
// Map an variable
context.insert(
"a".to_string(),
ContextEntry::Variable(Value::Number(24.into())),
);
// Map a function
context.insert(
"mul".to_string(),
ContextEntry::Function(Box::new(|args| {
let a = args[0].as_f64().unwrap();
Value::Number(Number::from_f64(a * 10.0).unwrap())
})),
);
let evaluator = Evaluator::new(context);
let res = evaluator.evaluate("a + mul(2)").unwrap();
assert_eq!(res, 44);