An opinionated cargo-generate template for Rust projects.
cargo generate gh:mlavrinenko/cratemplate
# or using nix:
nix run nixpkgs#cargo-generate -- generate --git https://github.com/mlavrinenko/cratemplateYou'll be prompted for project name, GitHub username, description, license, and
crate kind (bin or lib).
Language & toolchain
- Rust 2024 edition,
rust-toolchain.toml,rustfmt.toml, clippy atdenywithclippy.tomlthresholds - Either kind of crate: a
bingetsmain.rs, aclapCLI,assert_cmde2e tests and a cross-platform release matrix; alibdrops all of that and ships a publish-only release workflow
Quality gates
- Code coverage via
cargo-llvm-cov(70% minimum) — it merges child-process profraw, so subprocess-based CLI tests actually attribute - CRAP metric gate via
cargo-crap - Copy-paste gate via jscpd
- File size limits via linecop (500 lines Rust, 200 Markdown)
- Dependency drift detection via outdatty
- Unused dependency detection via
cargo-machete - Advisory, license and dependency-ban audit via
cargo-deny - MSRV asserted in CI against the
rust-versioninCargo.toml - Per-gate memoization via mmz: every arm of
just checkis skipped when its declared inputs are unchanged, which makes thejust install-hookspre-commit hook (a gate-freshness assertion, every commit) affordable
Testing
- Inline tests extraction via
ejectest - CLI integration testing with
assert_cmd+predicates - Mutation testing recipes via
cargo-mutants(a dev aid, never a gate)
Error handling & CLI
thiserrorfor library errors; for abin,anyhow+clap4 +env_logger
Nix dev environment
- Flake with
nix develop(rustc, cargo, clippy, rustfmt, just, rust-analyzer, nixd, ...) direnv/.envrcfor automatic shell activationJustfilewith common recipes (just check,just test,just cover,just crap, ...)just install-hooksfor a pre-commit gate
Docs & conventions
CHANGELOG.md(Keep a Changelog + SemVer)CONTRIBUTING.mdwith detailed conventionsAGENTS.mdwith rules for LLM agents- Multiple license support (MIT / Apache-2.0 / dual / GPL-3.0-only)
CI/CD
- GitHub Actions: CI (checks, coverage, dependency audit, MSRV), Pages deployment, cross-platform release + crates.io publish, all with pinned actions
dependabot.ymlfor automated action bumps
After making changes to the template, validate that it still produces a working project:
just validate bin # or: just validate lib
just mmz validate bin # same, memoized — free when template/ is unchangedThis generates a project of that kind in a temp directory and runs fmt, clippy, tests, build, coverage, CRAP gate, file size checks, cargo-deny and a sandboxed nix build against it. It also asserts the gate wiring: a second just check must leave every gate-tagged mmz rule fresh, mmz --is-fresh --tag gate must then pass without running anything, and just install-hooks must produce an executable hook. An arm of just check with no rule in .mmz/config.yaml fails validation instead of shipping.
Both kinds are validated — CI matrices bin and lib — because an unvalidated
template branch rots silently.