1 unstable release

0.1.0 Feb 11, 2025

#961 in Math

Download history 109/week @ 2025-02-11

109 downloads per month

MIT license

12KB
284 lines

CLAIR—Command Line Arithmetic in Rust

CLAIR is a small personal project for exploring the Rust programming language. It implements arithmetic operations on lines of string (currently only stdin, but support for files as input is planned). This is inspired by using awk for command line arithmetics.

Build

cargo build [--release]

Run

cargo run [--release] --bin={count,mean,product,sum} [</path/to/file/as/stdin] [--help]

or directly form target:

./target/release/{count,mean,product,sum}

Example

Count

$ ./target/release/count < Cargo.toml
24

# Reference:
$ wc -l Cargo.toml
24 Cargo.toml

Mean

$ shuf -i 1-100 | ./target/release/mean
50.5

# Reference:
$ shuf -i 1-100 | awk '{x += $1} END {print(x/100)}'
50.5

Product

$ shuf -i 1-6 | ./target/release/product
720

# Reference:
$ shuf -i 1-6 | awk 'BEGIN {x=1} {x *= $1} END {print(x)}'
720

Sum

$ shuf -i 1-100 | ./target/release/sum
5050

# Reference:
$ shuf -i 1-100 | awk '{x += $1} END {print(x)}'
5050

Dependencies

~1.1–1.7MB
~32K SLoC