1
0
Fork
You've already forked rust-lib-template
0
Template project for Rust libraries.
  • Rust 92.9%
  • Gherkin 7.1%
Rob Williamson 69a2ad3b4a
Add BDD and Linting
And don't keep `Cargo.lock` in git because lib users may have
different dependencies around when they come to use the lib.
2026年06月07日 11:45:57 +02:00
dev-app Add template structure. 2026年06月05日 20:22:52 +02:00
dev-tools Add template structure. 2026年06月05日 20:22:52 +02:00
src Add BDD and Linting 2026年06月07日 11:45:57 +02:00
tests Add BDD and Linting 2026年06月07日 11:45:57 +02:00
.gitignore Add BDD and Linting 2026年06月07日 11:45:57 +02:00
Cargo.toml Add BDD and Linting 2026年06月07日 11:45:57 +02:00
coverage-threshold Add template structure. 2026年06月05日 20:22:52 +02:00
IMPLEMENTATION_GUIDE.md Add template structure. 2026年06月05日 20:22:52 +02:00
LICENSE Rename the License. 2026年06月05日 20:23:05 +02:00
prek.toml Add BDD and Linting 2026年06月07日 11:45:57 +02:00
README.md Add template structure. 2026年06月05日 20:22:52 +02:00

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-features
  • cargo run -p dev-tools --bin cargo-covcheck

Run manually:

prek run --all-files

Contributing

  1. Format: cargo fmt
  2. Test: cargo test --all-features
  3. Verify Coverage & Mutations:
    • Coverage: cargo run -p dev-tools --bin cargo-covcheck
    • Mutation: cargo run -p dev-tools --bin cargo-mutcheck
  4. Hooks: Ensure prek run --all-files passes.
  5. 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