No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-02-25 16:11:59 +00:00
.github Add GitHub templates, update README 2017-06-30 12:36:49 -04:00
src Fix issue #29 'Multiply with parentheses wont work' 2024-02-21 23:30:14 +01:00
.gitignore Add Cargo.lock to tracked files 2017-10-25 19:11:04 -07:00
.gitlab-ci.yml Fix formatting. Try to fix gitlab CI pipeline. 2024-02-15 23:23:17 +01:00
.travis.yml Reformat, switch to cargo fmt -- --check 2018-06-02 11:45:47 -07:00
Cargo.lock Version bump to 0.8.0. 2024-02-22 21:45:24 +01:00
Cargo.toml Version bump to 0.8.0. 2024-02-22 21:45:24 +01:00
LICENSE Add RedoxOS license 2017-06-26 23:55:29 -04:00
README.md Version bump ... again 2017-10-25 20:51:49 -07:00
rustfmt.toml Reformat, switch to cargo fmt -- --check 2018-06-02 11:45:47 -07:00

calc

Build Status crates.io

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.

Usage

As a Library

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(),
        }
    }
}

As an Executable

$ cargo install calculate
...
$ calc