Crates.io | expr-lang |
lib.rs | expr-lang |
version | |
source | src |
created_at | 2024-11-24 22:21:08.373611 |
updated_at | 2024-11-29 22:16:43.174276 |
description | Implementation of expr language in Rust |
homepage | https://github.com/jdx/expr-lang |
repository | https://github.com/jdx/expr-lang |
max_upload_size | |
id | 1459663 |
Cargo.toml error: | TOML parse error at line 22, column 1 | 22 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Implementation of expr in rust.
use expr::{Context, Parser};
fn main() {
let mut p = Parser::new();
let mut ctx = Context::default();
ctx.insert("two".to_string(), 2);
let three: i64 = p.eval("1 + two", &ctx).unwrap().as_number().unwrap();
assert_eq!(three, 3);
p.add_function("add", |c| {
let mut sum = 0;
for arg in c.args {
sum += arg.as_number().unwrap();
}
Ok(sum.into())
});
let six: i64 = p.eval("add(1, two, 3)", &ctx).unwrap().as_number().unwrap();
assert_eq!(six, 6);
}