A small, dependency-free CLI that counts Rust source lines tokei-style — but with one extra trick: it splits the Code column into Impl and Test so you can see how much of a crate is production code versus tests.
The name is from the Greek μέτρον, "measure."
cargo install ambroslabs-metronThe crate is published as ambroslabs-metron; the installed binary is metron.
Or install the latest from git:
cargo install --git https://github.com/ambroslabs/metronOr build from a clone:
git clone https://github.com/ambroslabs/metron
cd metron
cargo build --release # binary at target/release/metronmetron [--per-file|-f|--ls|-l] [--sort KEY] [--reverse|-r] [PATH]PATH defaults to the current directory. metron walks every .rs file
under it (skipping target/ and dot-directories like .git) and prints a
table of line counts.
| Mode | Flag | Rows |
|---|---|---|
| By subdirectory | (default) | one row per top-level subdir under PATH; loose files go in a . row |
| List | --ls, -l |
one row per entry directly under PATH (files individually, subdirs aggregated) |
| Per file | --per-file, -f |
one row per .rs file, fully recursive |
--sort KEY where KEY is one of path (default), files, lines, code,
impl, test, comments, blanks. Numeric keys default to descending;
path defaults to ascending. --reverse / -r flips the chosen key's
default direction.
Each line is one of:
- blank — only whitespace
- comment — only
//or/* */comments plus whitespace - code — anything else
Strings, char literals, and comments are tracked while scanning so delimiters inside them don't fool the classifier.
Code lines are then split into impl vs test. A line counts as test if it is:
- inside a
#[cfg(test)]item body (brace-balanced), or - in a file declared from a parent module via
#[cfg(test)] mod NAME;, or - under a crate's
tests/orbenches/directory.
Everything else is impl.
Licensed under either of Apache-2.0 or MIT at your option.