A generic Rust library project template — usable via GitHub's "Use this
template" button. Toolchain managed with rustup, formatted with
rustfmt, linted with clippy, and driven with just
as a make alternative.
Looking for the binary/application variant? See the sibling template template-rust-bin.
- Toolchain management via
rustupandrust-toolchain.toml— running anycargo/rustccommand in this directory auto-installs the pinned channel and components (rustfmt,clippy) the first time. - Formatting via
rustfmt(rustfmt.toml). - Linting via
clippy(clippy.toml). - Task runner via
just(justfile), including doc build/check recipes. - CI via GitHub Actions: format check, clippy, doc build, and test
(incl. doctests) on Linux/macOS/Windows (
.github/workflows/ci.yml). - Dependabot for Cargo and GitHub Actions updates.
- Dual-licensed MIT OR Apache-2.0 — the Rust ecosystem convention.
Cargo already plays the role a separate build system (e.g. CMake) would play in other languages: it's both the build tool and the package manager, no extra layer needed. For scaffolding new repositories from this one, use GitHub's "Use this template" button (this repo is configured as a GitHub template repository).
-
rustup— installs and manages the Rust toolchain. -
just(optional but recommended):cargo install just # or: brew install just / pacman -S just / apt install just / ...
-
Click "Use this template" on GitHub (or
git clonethis repo), then rename it. -
Update the package name/description in
Cargo.tomland this README's title. -
Build & test:
just build just test -
Use it as a dependency from another crate:
[dependencies] template-rust-lib = { git = "https://github.com/<user>/template-rust-lib" } # or, once published to crates.io: # template-rust-lib = "0.1"
| Command | Description |
|---|---|
just build |
Debug build |
just test |
Run tests (including doctests) |
just fmt |
Format code |
just fmt-check |
Check formatting without modifying files |
just lint |
Run clippy with warnings denied |
just doc |
Build and open the docs |
just doc-check |
Build docs with warnings denied (broken links, etc.) |
just ci |
Run everything CI runs (fmt-check + lint + test + doc-check) |
just clean |
Remove build artifacts |
just watch |
Re-run checks on file change (needs cargo-watch) |
Run just with no arguments to list all recipes. Without just, the
equivalent cargo commands are in the justfile itself.
.
├── src/
│ └── lib.rs # crate root
├── rust-toolchain.toml # pinned toolchain (rustup)
├── rustfmt.toml # formatter config
├── clippy.toml # linter config
├── justfile # task runner
├── .editorconfig
├── .github/
│ ├── workflows/ci.yml
│ └── dependabot.yml
├── LICENSE-MIT
├── LICENSE-APACHE
└── Cargo.toml
Licensed under either of Apache License, Version 2.0 or MIT license at your option.