Skip to content

Repository files navigation

template-rust-lib

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.

Features

  • Toolchain management via rustup and rust-toolchain.toml — running any cargo/rustc command 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).

Prerequisites

  • rustup — installs and manages the Rust toolchain.

  • just (optional but recommended):

    cargo install just
    # or: brew install just / pacman -S just / apt install just / ...

Getting started

  1. Click "Use this template" on GitHub (or git clone this repo), then rename it.

  2. Update the package name/description in Cargo.toml and this README's title.

  3. Build & test:

    just build
    just test
  4. 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"

Development

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.

Project structure

.
├── 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

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

Generic Rust library project template — rustup, rustfmt, clippy, just, GitHub Actions CI.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages