Skip to main content

Rust Project Template

Crates.io Crates.io Downloads npm version npm downloads PyPI version PyPI downloads rust tests code-quality license PRs

🚀 A production‑ready Rust project template to bootstrap new projects fast. It includes a clean Cargo layout, Docker, and a complete CI/CD suite.

Click Use this template to start a new repository from this scaffold.

Other Languages: English | 繁體中文 | 简体中文

🎯 Using This Template

IMPORTANT: This is a template repository. Before using it for your project, you must:

  1. Rename all occurrences of rust_template to your project name across the entire codebase
  2. Update metadata in Cargo.toml, cli/nodejs/package.json, and cli/python/pyproject.toml
  3. Update author information in all package manifests and Dockerfiles
  4. Update repository URLs in README badges, package manifests, and GitHub workflows
  5. Rename the Python package directory from cli/python/src/rust_template to your project name

For detailed step-by-step instructions, see CLAUDE.md.

Quick verification after setup:

grep -r "rust_template" . --exclude-dir=target --exclude-dir=.git  # Should find minimal matches
make fmt && cargo build && cargo test --all  # Verify everything works

✨ Highlights

  • Modern Cargo layout with unit tests in src/ and integration tests in tests/
  • Dynamic version information with git metadata (tag, commit hash, build tools)
  • Lint & format with clippy and rustfmt
  • GitHub Actions: tests, quality, package build, Docker publish, release drafter, Rust-aware labeler, secret scans, semantic PR, weekly dependency update
  • Multi-stage Dockerfile producing a minimal runtime image

🚀 Quick Start

Requirements:

  • Rust 1.85 or higher (using Edition 2024)
  • Docker (optional)

Install Rust via rustup if you haven't already.

make fmt            # rustfmt + clippy
make test           # cargo test (all targets)
make test-verbose   # cargo test (all targets with verbose output)
make coverage       # generate LCOV coverage report
make build          # cargo build (release mode)
make build-release  # cargo build --release
make run            # run the release binary
make clean          # clean build artifacts and caches
make package        # build crate package (allow dirty)
make help           # list targets

📌 Version Information

The binary automatically displays dynamic version information including:

  • Git tag version (or Cargo.toml version if no tags)
  • Commit count since last tag
  • Short commit hash
  • Dirty working directory indicator
  • Rust and Cargo versions used for building

Example output:

rust_template v0.1.25-2-gf4ae332-dirty
Built with Rust 1.90.0 and Cargo 1.90.0

This version information is embedded at build time through build.rs and automatically updated based on your git state.

🧪 Testing Layout

This template follows Rust's idiomatic test organization:

  • Unit tests live next to the code they verify inside src/src/lib.rs wraps them in a #[cfg(test)] mod tests { ... } block and groups them into one sub-module per tested function (tests::add, tests::multiply, tests::version_info, ...). They can exercise private items.
  • Integration tests live in the top-level tests/ directory. Each file is compiled as its own crate and may only use the public API, and files are split by topic:

Run everything with make test (or cargo test --all).

🐳 Docker

docker build -f docker/Dockerfile --target prod -t ghcr.io/<owner>/<repo>:latest .
docker run --rm ghcr.io/<owner>/<repo>:latest

Or using the actual binary name:

docker build -f docker/Dockerfile --target prod -t rust_template:latest .
docker run --rm rust_template:latest

📦 Packaging

make package        # build crate package (allow dirty)
# or use cargo directly:
cargo package --locked --allow-dirty
# CARGO_REGISTRY_TOKEN=... cargo publish

CI builds run automatically on tags matching v* and upload the .crate file. Uncomment the publish step in build_package.yml to automate crates.io releases.

🧩 Cross Builds

This template does not ship cross-compile tooling by default. If you need cross or zig-based builds locally, install and configure them per your environment.

GitHub Actions build_release.yml builds multi-platform release binaries on tags matching v* and uploads them to the GitHub Release assets.

Targets:

  • x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl
  • aarch64-unknown-linux-gnu, aarch64-unknown-linux-musl
  • x86_64-apple-darwin, aarch64-apple-darwin
  • x86_64-pc-windows-msvc, aarch64-pc-windows-msvc

Assets naming:

  • <bin>-v<version>-<target>.tar.gz (all platforms)
  • <bin>-v<version>-<target>.zip (Windows additionally)

🔁 CI/CD Workflows

Main Workflows

  • Tests (test.yml): cargo build/test + generate LCOV coverage report and upload artifact
  • Code Quality (code-quality-check.yml): rustfmt check + clippy (deny warnings)
  • Build Package (build_package.yml): package on tag v*, optional crates.io publish
  • Publish Docker Image (build_image.yml): push to GHCR on main/master and tags v*
  • Build Release (build_release.yml): Linux release binaries uploaded on tags v*

Additional Automation

  • Auto Labeler (auto_labeler.yml): automatically label PRs based on branch names and file changes
  • Code Scan (code_scan.yml): multi-layer security scanning (GitLeaks, Trufflehog secret scanning, CodeQL code analysis)
  • Release Drafter (release_drafter.yml): auto-generate release notes
  • Semantic PR (semantic-pull-request.yml): enforce PR title format
  • Dependabot weekly dependency updates

🤝 Contributing

  • Open issues/PRs

  • Use Conventional Commits for PR titles

  • Keep code formatted and clippy‑clean

  • After every edit, run cargo build to confirm compilation is successful

  • Before opening a PR, please run locally:

    • cargo fmt --all -- --check
    • cargo clippy --all-targets --all-features -- -D warnings
    • cargo test

📄 License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rust_template-0.2.11.tar.gz (806.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rust_template-0.2.11-py3-none-any.whl (807.1 kB view details)

Uploaded Python 3

File details

Details for the file rust_template-0.2.11.tar.gz.

File metadata

  • Download URL: rust_template-0.2.11.tar.gz
  • Upload date:
  • Size: 806.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rust_template-0.2.11.tar.gz
Algorithm Hash digest
SHA256 1014a1e3cee989fdf849cf956498e5b53916c879ceb140a4e71a7dc5c5433cf5
MD5 270c4b4d858fff79350fcc02db2ec2eb
BLAKE2b-256 c0701285310e1ea738b81cff447a8a96821ee550ddd46129e48f8929c1cc7b72

See more details on using hashes here.

File details

Details for the file rust_template-0.2.11-py3-none-any.whl.

File metadata

  • Download URL: rust_template-0.2.11-py3-none-any.whl
  • Upload date:
  • Size: 807.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.0 {"installer":{"name":"uv","version":"0.12.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for rust_template-0.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 4ee05bf848f324883051e6c7a388cde67793414f6d7e4696c38fc48786998708
MD5 82112f2b1ecb5eb8b3d90149c1c74c44
BLAKE2b-256 77b1ceae163cd267f2a6fde70670a10276a53e59137646b2990fbf98a362194f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.12

2 files

This release

0.2.11 This release

2 files

0.2.10

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.39

2 files

0.1.38

2 files

0.1.37

2 files

0.1.36

2 files

0.1.34

2 files

0.1.33

2 files

0.1.32

2 files

0.1.31

2 files

0.1.30

2 files

0.1.29

2 files

0.1.28

2 files

0.1.27

2 files

0.1.26

2 files

0.1.25

2 files

0.1.24

2 files

0.1.23

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page