Template project for Rust libraries.
|
Rob Williamson
69a2ad3b4a
And don't keep `Cargo.lock` in git because lib users may have different dependencies around when they come to use the lib. |
||
|---|---|---|
| dev-app | Add template structure. | |
| dev-tools | Add template structure. | |
| src | Add BDD and Linting | |
| tests | Add BDD and Linting | |
| .gitignore | Add BDD and Linting | |
| Cargo.toml | Add BDD and Linting | |
| coverage-threshold | Add template structure. | |
| IMPLEMENTATION_GUIDE.md | Add template structure. | |
| LICENSE | Rename the License. | |
| prek.toml | Add BDD and Linting | |
| README.md | Add template structure. | |
Rust Library Template
A minimal Rust library template with branch coverage enforcement, mutation testing, and a dev binary to exercise the library.
How to Build & Run
Prerequisites
Install Rust, then install coverage and pre-commit tools:
# Nightly toolchain + cargo-llvm-cov for branch coverage
rustup toolchain install nightly
rustup component add llvm-tools --toolchain nightly
cargo install cargo-llvm-cov
# cargo-mutants for mutation testing
cargo install cargo-mutants
# prek for pre-commit hooks
cargo install prek
Building & Running
cargo build # Debug build
cargo build --release # Release build
cargo run -p dev-app # Run the dev application
Testing
cargo test --all-features
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.
Publishing
Ensure Cargo.toml has description, license, repository, and readme set, then:
cargo login # one-time: authenticate with crates.io
cargo publish --dry-run # verify the package before release
cargo publish