A Rust binary template project with bits and pieces that are annoying to add separately.
| dev-tools | Move the Dev Tools | |
| src | Correct Clippy interventions. | |
| tests | Move the Dev Tools | |
| .gitignore | Move the Dev Tools | |
| Cargo.lock | Move the Dev Tools | |
| Cargo.toml | Move the Dev Tools | |
| coverage-threshold | Initial Commit | |
| LICENSE | Reset the license. It should be a choice for the template user. | |
| prek.toml | Add builtins and clippy, also clean before measuring coverage. | |
| README.md | Move the Dev Tools | |
Rust Bin Template
A Rust binary template with branch coverage enforcement, mutation testing, and a pre-commit pipeline via prek.
How to Build & Run
Prerequisites
Install Rust, then install coverage and pre-commit tools:
# Install cargo-llvm-cov & nightly toolchain for coverage
rustup toolchain install nightly
rustup component add llvm-tools --toolchain nightly
cargo install cargo-llvm-cov
# Install cargo-mutants for mutation testing
cargo install cargo-mutants
# Install prek
cargo install prek
Building & Running
cargo build # Debug build
cargo build --release # Release build
cargo run # Run the CLI binary
CLI Commands
cargo run -- add "Buy milk"
cargo run -- list
cargo run -- complete 0
cargo run -- delete 0
Testing
Run all unit tests:
cargo test --all-features
- Unit tests: Located in
src/lib.rsanddev-tools/src/bin/cargo-covcheck.rs.
Coverage & Mutation Testing
Branch Coverage
cargo run -p dev-tools --bin cargo-covcheck
Threshold is set in coverage-threshold. Results via cargo +nightly llvm-cov --branch --html.
Mutation Testing
cargo run -p dev-tools --bin cargo-mutcheck
Review mutants.out/missed.txt for surviving mutations; strengthen tests accordingly.
Pre-commit Hooks
Set up hooks in this repository:
prek install
Once set up, these checks run automatically on every commit:
cargo fmt --check(auto-formats on failure)cargo test --all-featurescargo run -p dev-tools --bin cargo-covcheck
Run manually:
prek run --all-files
Contributing
- Format:
cargo fmt - Test:
cargo test --all-features - Verify Coverage & Mutations:
- Coverage:
cargo run -p dev-tools --bin cargo-covcheck - Mutation:
cargo run -p dev-tools --bin cargo-mutcheck
- Coverage:
- Hooks: Ensure
prek run --all-filespasses. - Open a Pull Request with your changes.
Workspace Structure
src/- Main library and binarydev-tools/- Helper utilities for coverage and mutation testing