Math expression parser and evaluation library for Rust
Math expression parser and evaluation library for Rust
This [Rust] crate provides a simple math expression parsing and evaluation. Its main goal is to
be convenient to use, while allowing for some flexibility. Currently works only with f64
types. A typical use case is the configuration of numerical computations in
Rust, think initial data and boundary conditions, via config files or command line arguments.
Simply add the corresponding entry to your Cargo.toml dependency list:
[dependencies]
meval = "0.2"Requires Rust 1.26.
fn main() {
let r = meval::eval_str("1 + 2").unwrap();
println!("1 + 2 = {}", r);
}Need to define a Rust function from an expression? No problem, use Expr
for this and more:
fn main() {
let expr: meval::Expr = "sin(pi * x)".parse().unwrap();
let func = expr.bind("x").unwrap();
let vs: Vec = (0..100+1).map(|i| func(i as f64 / 100.)).collect();
println!("sin(pi * x), 0
number_ "converter". For more advanced uses, see:
- [evalexpr] -- A more complete expression evaluator that supports value
types, boolean operators, strings, assignment operators, ...
- [dyon] -- A rusty dynamically typed scripting language
- [gluon] -- A static, type inferred programming language for application embedding
- [rodolf0/tox](https://github.com/rodolf0/tox) -- another shunting yard expression parser
[Rust]: https://www.rust-lang.org/
[std-float]: http://doc.rust-lang.org/stable/std/primitive.f64.html
[serde]: https://crates.io/crates/serde
[evalexpr]: https://crates.io/crates/evalexpr
[dyon]: https://crates.io/crates/dyon
[gluon]: https://crates.io/crates/gluon
## License
This project is dual-licensed under the Unlicense and MIT licenses.
You may use this code under the terms of either license.No open issues yet, or sync has not completed.