A simple and efficient mathematical expression interpreter in Rust.
Operators Supported:
- Addition (
+
) - Subtraction (
-
) - Multiplication (
*
) - Division (
/
) - Exponentiation (
**
)
Here's a basic example of how to use SimpleCalc:
fn main() {
match simplecalc::eval("1+2-3*4/5**6") {
Ok(res) => println!("{res}"),
Err(e) => println!("{e}"),
}
}
Evaluate an expression:
let result = simplecalc::eval("10 + 5 * 2")?;
println!("{}", result); // Outputs: 20
Handle invalid expressions:
println!("{}", simplecalc::eval("invalud expression").err().unwrap());