• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H31-Jul-2019-4222

src/H31-Jul-2019-1,8841,596

.gitignoreH A D31-Jul-2019329 1310

.gitlab-ci.ymlH A D31-Jul-2019317 1311

.travis.ymlH A D31-Jul-2019208 1413

Cargo.lockH A D31-Jul-201921.8 KiB490436

Cargo.tomlH A D03-May-2022829 4036

LICENSEH A D31-Jul-20191.1 KiB2317

README.mdH A D31-Jul-20191.2 KiB4836

rustfmt.tomlH A D31-Jul-201967 43

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