Skip to content

Configuration

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.

PlaceholderReplaced WithExample
zircote/rust-templateyour-org/your-repo (full path)acme/my-cli
zircote/rust_templateyour-org/your_crate (full path, underscored)acme/my_cli
zircoteYour GitHub org or usernameacme
rust-templateYour repo name (hyphenated)my-cli
rust_templateYour crate name (underscored)my_cli
  1. You click “Use this template” on GitHub.
  2. You push to main (or the initial commit triggers the workflow).
  3. The workflow detects name = "rust_template" in Cargo.toml.
  4. It runs sed replacements across all eligible files.
  5. It regenerates Cargo.lock and 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 files
  • Cargo.lock — Regenerated after replacement

If you need to run replacement manually (e.g., you disabled Actions), use:

Terminal window
# 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-lockfile

After placeholder replacement runs, review and update these fields in Cargo.toml:

FieldDefaultAction
namerust_templateAuto-replaced by template-init
version0.1.0Update for releases
edition2024Leave as-is unless you need an older edition
rust-version1.92Update 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
repositoryhttps://github.com/zircote/rust-templateAuto-replaced by template-init
homepagehttps://github.com/zircote/rust-templateAuto-replaced by template-init
documentationhttps://docs.rs/rust_templateAuto-replaced by template-init
licenseMITChange 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 authors with your real name/email
  • Write a meaningful description
  • Replace keywords with terms relevant to your crate
  • Choose appropriate categories from the crates.io category list
  • Verify license matches your LICENSE file
  • 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"] }
  1. Open Cargo.toml.
  2. Uncomment the relevant lines under [dependencies] and [dev-dependencies].
  3. Run cargo check to verify resolution.
  4. If the dependency has a restrictive license, add it to the allow list in deny.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,
}
Terminal window
# 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.

SettingDefaultPurpose
msrv"1.92"Minimum Rust version for lint suggestions
cognitive-complexity-threshold25Max cognitive complexity per function
too-many-lines-threshold100Max lines per function
too-many-arguments-threshold7Max function parameters
excessive-nesting-threshold4Max nesting depth
max-struct-bools3Max bool fields in a struct
allow-unwrap-in-teststruePermit .unwrap() in test code
allow-expect-in-teststruePermit .expect() in test code

Controls code formatting rules.

SettingDefaultPurpose
edition"2024"Parsing edition
max_width100Maximum line width
tab_spaces4Spaces per indentation level
imports_granularity"Crate"How imports are grouped
group_imports"StdExternalCrate"Import section ordering
wrap_commentstrueWrap long comments
format_code_in_doc_commentstrueFormat code blocks in doc comments
trailing_comma"Vertical"Add trailing commas in multi-line contexts

Controls dependency auditing via cargo-deny.

SectionWhat to Customize
[advisories]Add crate IDs to ignore to suppress known advisories
[licenses].allowAdd SPDX identifiers for licenses your project permits
[bans].denyAdd crates you want to forbid (e.g., openssl)
[bans].skipAllow specific duplicate dependency versions
[sources].allow-gitAdd 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 instead

To 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:

FileFieldExample
Cargo.tomlrust-versionrust-version = "1.85"
clippy.tomlmsrvmsrv = "1.85"
CI workflow matrixrust: versionsAdd your MSRV to the test matrix
Terminal window
# Install a specific toolchain to verify MSRV
rustup install 1.85
cargo +1.85 check
cargo +1.85 test

Cross-editor defaults applied automatically by editors that support EditorConfig:

SettingValueScope
indent_stylespaceAll files
indent_size4Default (2 for YAML/JSON)
max_line_length100All files
end_of_linelfAll files
charsetutf-8All files
insert_final_newlinetrueAll files
trim_trailing_whitespacetrueAll files (except Markdown)

VS Code workspace settings:

  • rust-analyzer.check.command set to clippy (lints on save)
  • rust-analyzer.check.extraArgs includes --all-targets --all-features
  • editor.formatOnSave enabled
  • editor.rulers set to [100] to show the line-length guide
  • target/ directory excluded from file explorer

Recommended extensions (VS Code prompts to install these):

ExtensionPurpose
rust-lang.rust-analyzerRust language server
tamasfe.even-better-tomlTOML syntax and validation
serayuzgur.cratesInline crate version info
usernamehw.errorlensInline error/warning display
vadimcn.vscode-lldbNative 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 runs cargo 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 custom Dockerfile
  • 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:

FileScope
rust-code.instructions.mdRust source files (crates/**/*.rs)
tests.instructions.mdTest files (tests/**/*.rs)

Reusable prompt files for common development tasks:

PromptPurpose
new-module.prompt.mdScaffold a new Rust module
fix-clippy.prompt.mdFix Clippy lint warnings
add-error-variant.prompt.mdAdd a new error type variant
write-tests.prompt.mdGenerate tests for existing code
  • Edit CLAUDE.md and AGENTS.md at the repo root to update project-wide conventions.
  • Add new .instructions.md files under .github/instructions/ for path-specific rules.
  • Add new .prompt.md files under .github/prompts/ for reusable task prompts.
  • All AI instruction files are regular Markdown — placeholder replacement applies to them automatically.