clair

Crates.ioclair
lib.rsclair
version0.1.0
created_at2025-02-11 03:24:21.574017+00
updated_at2025-02-11 03:24:21.574017+00
descriptionCommand-Line Arithmetic in Rust
homepage
repositoryhttps://github.com/hanslovsky/clair
max_upload_size
id1550949
size19,451
Philipp Hanslovsky (hanslovsky)

documentation

README

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
Commit count: 14

cargo fmt