README.md
1# calc
2[![Build Status](https://travis-ci.org/redox-os/calc.svg?branch=master)](https://travis-ci.org/redox-os/calc)
3[![crates.io](https://meritbadge.herokuapp.com/calculate)](https://crates.io/crates/calculate)
4
5
6`calc` is a Rust library for tokenizing and evaluating arithmetic expressions with a command line application of the same name included.
7
8**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.
9
10# Usage
11
12## As a Library
13
14Add `calc` as a dependency in your `Cargo.toml`:
15```toml
16[dependencies]
17calculate = "0.5.*"
18```
19
20Then make use of the library functions:
21```rust
22extern crate calc;
23
24use calc::eval;
25use std::io::{self, BufRead, stdout, stdin, Write};
26
27fn main() {
28 let stdout = stdout();
29 let mut stdout = stdout.lock();
30 let stdin = stdin();
31 for line in stdin.lock().lines() {
32 match line.unwrap().trim() {
33 "" => (),
34 "exit" => break,
35 s => writeln!(stdout, "{}", eval(s)).unwrap(),
36 }
37 }
38}
39```
40
41## As an Executable
42
43```bash
44$ cargo install calculate
45...
46$ calc
47```
48