Cargo and Workspace Patterns
Use this recipe when creating a new Rust project, refactoring into a workspace, or editing Cargo.toml.
New Binary Crate
[package]
name = "service-name"
version = "0.1.0"
edition = "2024"
rust-version = "1.90"
license = "MIT OR Apache-2.0"
publish = false
[dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros", "signal", "sync", "time"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] }Use rust-version = "1.90" as this skill's default floor for new projects (see the baseline in SKILL.md). Drop to 1.85 only when bare Rust 2024 compatibility is the explicit MSRV requirement, and prefer a current stable toolchain when no MSRV constraint exists.
rust-toolchain.toml
Use a floating stable channel for normal greenfield development:
[toolchain]
channel = "stable"
components = ["rustfmt", "clippy"]Use an exact pin only when reproducibility matters more than automatic patch updates:
[toolchain]
channel = "1.95.0"
components = ["rustfmt", "clippy"]When pinning to a concrete version, verify it is still the intended current or supported version before generating the file.
Virtual Workspace
For repositories with more than one crate:
[workspace]
resolver = "3"
members = ["crates/*"]
[workspace.package]
edition = "2024"
rust-version = "1.90"
license = "MIT OR Apache-2.0"
publish = false
[workspace.dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
tokio = { version = "1", features = ["rt-multi-thread", "macros", "signal", "sync", "time"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt", "json"] }
[workspace.lints.rust]
warnings = "deny"
unsafe_code = "forbid"
[workspace.lints.clippy]
unwrap_used = "warn"
expect_used = "warn"
panic = "warn"
print_stdout = "warn"
uninlined_format_args = "warn"
missing_errors_doc = "warn"Rust 2024 implies resolver 3 for normal packages, but virtual workspaces should set resolver = "3" explicitly.
Member Crate
[package]
name = "my-core"
version = "0.1.0"
edition.workspace = true
rust-version.workspace = true
license.workspace = true
publish.workspace = true
[dependencies]
serde.workspace = true
thiserror.workspace = true
tracing.workspace = true
[lints]
workspace = trueRelease Profiles
For deployable binary crates:
[profile.release]
strip = "symbols"
lto = "thin"
codegen-units = 1
panic = "abort"Guidance:
- Prefer
lto = "thin"before full LTO unless maximum size/performance is required. - Use
panic = "abort"only for binaries where unwinding is not required. - Avoid forcing release profile choices in libraries.
Feature Flags
Keep feature names descriptive and additive:
[features]
default = []
otlp = ["dep:opentelemetry", "dep:opentelemetry_sdk", "dep:opentelemetry-otlp", "dep:tracing-opentelemetry"]
azure = ["dep:azure_identity"] # azure_identity reached GA 1.0.0 on 2026-05-12 (Azure SDK for Rust)Rules:
- Features should not silently disable behavior.
- Prefer optional dependencies behind explicit features for telemetry, cloud SDKs, databases, and transport integrations.
- Do not expose feature names like
use_fooorwith_bar; use the capability name.