Crates.io | calculate |
lib.rs | calculate |
version | 0.5.1 |
source | src |
created_at | 2017-07-06 01:22:11.974143 |
updated_at | 2017-11-13 01:51:02.576328 |
description | Rust library for parsing and processing arithmetic expressions |
homepage | https://github.com/redox-os/calc |
repository | https://github.com/redox-os/calc |
max_upload_size | |
id | 22126 |
size | 51,153 |
calc
is a Rust library for tokenizing and evaluating arithmetic expressions with a command line application of the same name included.
NOTE: The name of the project, binary, and library are calc
but the package name is calculate
. This will remain depending on if this project can acquire the calc
crate which is currently being squatted on.
Add calc
as a dependency in your Cargo.toml
:
[dependencies]
calculate = "0.5.*"
Then make use of the library functions:
extern crate calc;
use calc::eval;
use std::io::{self, BufRead, stdout, stdin, Write};
fn main() {
let stdout = stdout();
let mut stdout = stdout.lock();
let stdin = stdin();
for line in stdin.lock().lines() {
match line.unwrap().trim() {
"" => (),
"exit" => break,
s => writeln!(stdout, "{}", eval(s)).unwrap(),
}
}
}
$ cargo install calculate
...
$ calc