| diataxis_type | how-to |
|---|
How to configure your new repository after creating it from the rust-template.
This guide covers every customization point in the template, from automatic placeholder replacement to editor and AI assistant configuration.
The template-init.yml workflow runs automatically on the first push to main after you create a repo from this template. It replaces all template placeholders with your project's values.
| Placeholder | Replaced With | Example |
|---|---|---|
zircote/rust-template |
your-org/your-repo (full path) |
acme/my-cli |
zircote/rust_template |
your-org/your_crate (full path, underscored) |
acme/my_cli |
zircote |
Your GitHub org or username | acme |
rust-template |
Your repo name (hyphenated) | my-cli |
rust_template |
Your crate name (underscored) | my_cli |
- You click "Use this template" on GitHub.
- You push to
main(or the initial commit triggers the workflow). - The workflow detects
name = "rust_template"inCargo.toml. - It runs
sedreplacements across all eligible files. - It regenerates
Cargo.lockand commits the result.
The workflow skips these paths to avoid corrupting binaries or breaking CI:
.git/*-- Git internals.github/workflows/*-- CI workflow files*.png,*.jpg,*.ico-- Binary image filesCargo.lock-- Regenerated after replacement
If you need to run replacement manually (e.g., you disabled Actions), use:
# Set your values
OWNER="your-org"
REPO="your-repo"
CRATE="$(echo "$REPO" | tr '-' '_')"
# Replace in all text files (macOS sed)
find . -type f \
! -path './.git/*' \
! -path './.github/workflows/*' \
! -name '*.png' ! -name '*.jpg' ! -name '*.ico' \
! -name 'Cargo.lock' \
-exec sed -i '' \
-e "s|zircote/rust-template|${OWNER}/${REPO}|g" \
-e "s|zircote/rust_template|${OWNER}/${CRATE}|g" \
-e "s|zircote|${OWNER}|g" \
-e "s|rust-template|${REPO}|g" \
-e "s|rust_template|${CRATE}|g" \
{} +
cargo generate-lockfileAfter placeholder replacement runs, review and update these fields in Cargo.toml:
| Field | Default | Action |
|---|---|---|
name |
rust_template |
Auto-replaced by template-init |
version |
0.1.0 |
Update for releases |
edition |
2024 |
Leave as-is unless you need an older edition |
rust-version |
1.92 |
Update if changing MSRV (see section 6) |
authors |
["Your Name <you@example.com>"] |
Replace with your name and email |
description |
"A Rust template crate..." |
Replace with your crate's description |
repository |
https://github.com/zircote/rust-template |
Auto-replaced by template-init |
homepage |
https://github.com/zircote/rust-template |
Auto-replaced by template-init |
documentation |
https://docs.rs/rust_template |
Auto-replaced by template-init |
license |
MIT |
Change if using a different license |
keywords |
["template", "rust", "example"] |
Replace with up to 5 relevant keywords |
categories |
["development-tools"] |
Replace with applicable crate categories |
- Update
authorswith your real name/email - Write a meaningful
description - Replace
keywordswith terms relevant to your crate - Choose appropriate
categoriesfrom the crates.io category list - Verify
licensematches yourLICENSEfile - Remove the
[[bin]]section if building a library-only crate
The template Cargo.toml includes commented-out dependency blocks. Uncomment what you need:
[dependencies]
tokio = { version = "1.0", features = ["full"] }
[dev-dependencies]
tokio-test = "0.4"[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"[dependencies]
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }Add clap manually -- it is not pre-included in the template:
[dependencies]
clap = { version = "4", features = ["derive"] }- Open
Cargo.toml. - Uncomment the relevant lines under
[dependencies]and[dev-dependencies]. - Run
cargo checkto verify resolution. - If the dependency has a restrictive license, add it to the
allowlist indeny.toml.
The template includes an empty feature flags section in Cargo.toml:
[features]
default = []
# full = ["feature1", "feature2"][features]
default = []
async = ["dep:tokio", "dep:tokio-test"]
serde = ["dep:serde", "dep:serde_json"]
full = ["async", "serde"]Gate modules and items behind feature flags with cfg attributes:
#[cfg(feature = "async")]
pub mod async_client;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[cfg(feature = "serde")]
#[derive(Serialize, Deserialize)]
pub struct Config {
pub name: String,
}# Build with a specific feature
cargo build --features async
# Build with all features
cargo build --all-features
# Test with no default features
cargo test --no-default-features
# Test with a combination
cargo test --features "async,serde"The template CI runs cargo clippy --all-targets --all-features and cargo test --all-features by default. If your features are mutually exclusive, update the CI workflow matrix to test each combination separately.
Three configuration files control code quality rules. Adjust them to match your project's requirements.
Controls Clippy lint behavior and thresholds.
| Setting | Default | Purpose |
|---|---|---|
msrv |
"1.92" |
Minimum Rust version for lint suggestions |
cognitive-complexity-threshold |
25 |
Max cognitive complexity per function |
too-many-lines-threshold |
100 |
Max lines per function |
too-many-arguments-threshold |
7 |
Max function parameters |
excessive-nesting-threshold |
4 |
Max nesting depth |
max-struct-bools |
3 |
Max bool fields in a struct |
allow-unwrap-in-tests |
true |
Permit .unwrap() in test code |
allow-expect-in-tests |
true |
Permit .expect() in test code |
Controls code formatting rules.
| Setting | Default | Purpose |
|---|---|---|
edition |
"2024" |
Parsing edition |
max_width |
100 |
Maximum line width |
tab_spaces |
4 |
Spaces per indentation level |
imports_granularity |
"Crate" |
How imports are grouped |
group_imports |
"StdExternalCrate" |
Import section ordering |
wrap_comments |
true |
Wrap long comments |
format_code_in_doc_comments |
true |
Format code blocks in doc comments |
trailing_comma |
"Vertical" |
Add trailing commas in multi-line contexts |
Controls dependency auditing via cargo-deny.
| Section | What to Customize |
|---|---|
[advisories] |
Add crate IDs to ignore to suppress known advisories |
[licenses].allow |
Add SPDX identifiers for licenses your project permits |
[bans].deny |
Add crates you want to forbid (e.g., openssl) |
[bans].skip |
Allow specific duplicate dependency versions |
[sources].allow-git |
Add Git repository URLs for non-crates.io dependencies |
The [lints.clippy] section in Cargo.toml sets lint levels. Key denied lints:
unwrap_used = "deny" # Use Result instead
expect_used = "deny" # Use Result instead
panic = "deny" # No panics in library code
todo = "deny" # No incomplete code
unimplemented = "deny" # No stubs
dbg_macro = "deny" # No debug macros
print_stdout = "deny" # Use tracing/log instead
print_stderr = "deny" # Use tracing/log insteadTo relax a lint for your project, change "deny" to "warn" or "allow".
The current minimum supported Rust version is 1.92.
Update all three locations to keep them in sync:
| File | Field | Example |
|---|---|---|
Cargo.toml |
rust-version |
rust-version = "1.85" |
clippy.toml |
msrv |
msrv = "1.85" |
| CI workflow matrix | rust: versions |
Add your MSRV to the test matrix |
# Install a specific toolchain to verify MSRV
rustup install 1.85
cargo +1.85 check
cargo +1.85 testCross-editor defaults applied automatically by editors that support EditorConfig:
| Setting | Value | Scope |
|---|---|---|
indent_style |
space |
All files |
indent_size |
4 |
Default (2 for YAML/JSON) |
max_line_length |
100 |
All files |
end_of_line |
lf |
All files |
charset |
utf-8 |
All files |
insert_final_newline |
true |
All files |
trim_trailing_whitespace |
true |
All files (except Markdown) |
VS Code workspace settings:
rust-analyzer.check.commandset toclippy(lints on save)rust-analyzer.check.extraArgsincludes--all-targets --all-featureseditor.formatOnSaveenablededitor.rulersset to[100]to show the line-length guidetarget/directory excluded from file explorer
Recommended extensions (VS Code prompts to install these):
| Extension | Purpose |
|---|---|
rust-lang.rust-analyzer |
Rust language server |
tamasfe.even-better-toml |
TOML syntax and validation |
serayuzgur.crates |
Inline crate version info |
usernamehw.errorlens |
Inline error/warning display |
vadimcn.vscode-lldb |
Native debugger |
GitHub Codespaces and VS Code Dev Container configuration:
- Base image:
mcr.microsoft.com/devcontainers/rust:1-bookworm - Post-create command: installs
cargo-deny,cargo-tarpaulin,cargo-watch, and runscargo fetch - VS Code settings and extensions mirror the workspace configuration above
To customize the dev container, edit .devcontainer/devcontainer.json. Common changes:
- Add system packages via
"features"or a customDockerfile - Add environment variables with
"containerEnv" - Forward ports with
"forwardPorts" - Install additional cargo tools in
"postCreateCommand"
The template includes configuration files for multiple AI coding assistants.
Instructions for Claude Code. Located at the repo root.
- Build commands, project structure, and code style rules
- Error handling patterns and documentation requirements
- Testing conventions and CI/CD pipeline details
Instructions for GitHub Copilot coding agent. Located at the repo root.
- Read by the Copilot coding agent when it works on issues and PRs
- Shares the same project conventions as
CLAUDE.md
Instructions for GitHub Copilot Chat. Loaded automatically in Copilot Chat conversations.
- Provides project-wide context for inline suggestions and chat responses
Path-specific instruction files applied when Copilot works on matching file paths:
| File | Scope |
|---|---|
rust-code.instructions.md |
Rust source files (crates/**/*.rs) |
tests.instructions.md |
Test files (tests/**/*.rs) |
Reusable prompt files for common development tasks:
| Prompt | Purpose |
|---|---|
new-module.prompt.md |
Scaffold a new Rust module |
fix-clippy.prompt.md |
Fix Clippy lint warnings |
add-error-variant.prompt.md |
Add a new error type variant |
write-tests.prompt.md |
Generate tests for existing code |
- Edit
CLAUDE.mdandAGENTS.mdat the repo root to update project-wide conventions. - Add new
.instructions.mdfiles under.github/instructions/for path-specific rules. - Add new
.prompt.mdfiles under.github/prompts/for reusable task prompts. - All AI instruction files are regular Markdown -- placeholder replacement applies to them automatically.