https://github.com/j-zhengli/calculator_util
A crate that make it easier to write calculator app.
https://github.com/j-zhengli/calculator_util
Last synced: 3 months ago
JSON representation
A crate that make it easier to write calculator app.
- Host: GitHub
- URL: https://github.com/j-zhengli/calculator_util
- Owner: J-ZhengLi
- License: mit
- Created: 2021-12-29T06:44:53.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-29T08:53:36.000Z (over 3 years ago)
- Last Synced: 2025-03-10T03:30:49.565Z (3 months ago)
- Language: Rust
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# calculator_util
A utility dependency that helps you solving mathmatical expressions.
[](https://crates.io/crates/calculator_util)
[](https://docs.rs/calculator_util)This crate provide implementation for Rust's string type, thus you can evaluate math expression by simply using `String.eval()` for supported format.
### Usage
Add this crate as dependency to your project's `Cargo.toml`.
```toml
[dependencies]
calculator_util = "0.1.2"
```### Example:
Evaluates a math expression.
```rust
use calculator_util::{ExprParser, number::Number};let equation = "(5+6) * 7".to_string();
let result = equation.eval();
assert_eq!(result, Number::from(77));
println!("{}", result); // 77
```Or just convert a math expression to postfix notation.
```rust
use calculator_util::ExprParser;let equation = "1 + 2 * 3 + -4/2".to_string();
let result: String = equation.to_postfix();
println!("{}", result); // "1 2 3 * + -4 2 / +"
```# License
This crate is distributed under the terms of MIT license.See [LICENSE](LICENSE) for details.