Rust + Cargo
Category: Tech Stack · Areas: all
Description
Category
tech-stack
Areas
all
Slot
language-runtime
Components
- Language: Rust (latest stable; MSRV pinned in
rust-toolchain.toml) - Build system: Cargo workspace (resolver = “2”)
- Edition: 2024
- Toolchain pinning:
rust-toolchain.tomlandworkspace.package.rust-versionmust stay in lockstep
Constraints
- All code must pass
cargo clippy --workspace --all-targets --no-deps -- -D warnings - All code must pass
cargo fmt --all -- --check - Workspace lints (
[workspace.lints]) are authoritative; every crate opts in via[lints] workspace = true unsafe_code = "deny"at the workspace level; anyunsafeblock requires a// SAFETY:comment and a local#[allow(unsafe_code)]- No
.unwrap()in library crates — use?or explicit error handling - Use
thiserrorfor library error types; useanyhowfor application/binary error handling - Public API items must have
///doc comments - All dependencies declared in
[workspace.dependencies]; crates reference with{ workspace = true } cargo deny checkmust pass (licenses, advisories, registry sources)cargo machetemust pass (no unused dependencies)- Repo-owned Rust commands run through a pinned-toolchain wrapper; do not rely on ambient
rustc/cargofrom PATH
Clippy Lint Policy
Workspace-level [workspace.lints.clippy]:
all,pedantic,nurseryatwarn(lint group baseline)unwrap_used,todo,unimplemented,dbg_macro,print_stdoutatdeny- Selected pedantic/nursery lints may be
allow-listed project-wide when they produce excessive noise; each allow must be documented in the workspaceCargo.toml
Workspace-level [workspace.lints.rust]:
unsafe_code = "deny"unused_must_use = "deny"missing_docs = "warn"dead_code = "warn"
Profile Conventions
[profile.dev]: fast builds,debug = 1, deps atopt-level = 1[profile.release]:lto = "thin",codegen-units = 8,strip = true[profile.release-dist](CI only):lto = "fat",codegen-units = 1,panic = "abort"[profile.profiling]: inherits release,debug = 1,strip = false
When to use
Performance-critical systems, CLI tools, infrastructure software, and projects
where memory safety and zero-cost abstractions matter. The workspace lint policy
above is the minimum bar; projects may tighten further via [profile] or
additional deny-level lints.
Artifact Impact
Selecting this concern requires these artifacts to change (a selected concern absent from them is drift):
- ADR: Rust + Cargo workspace (clippy, fmt, cargo-deny/machete, pinned toolchain) as the language-runtime
- TD: workspace lints, error-handling (thiserror/anyhow), unsafe policy, profile conventions
Practices by activity
Agents working in any of these activities inherit the practices below through runtime work context, such as a DDx bead context digest.
Requirements (Frame activity)
- Specify MSRV explicitly; it must be stable enough for CI and local dev
- Identify crates that are libraries vs binaries — error handling strategy differs
- If concurrency correctness is a requirement, plan for
loom-based testing
Design
- Organize as a Cargo workspace; every logical component is its own crate
- All inter-crate dependencies declared in
[workspace.dependencies] - Separate
crates/(libraries) fromtools/orbin/(binaries/CLIs) in workspace layout - Design error types using
thiserrorfor library crates; surface errors withanyhowin binaries - Prefer newtypes and strong typing over stringly-typed parameters
- Concurrent state: prefer
Arc<Mutex<T>>ordashmapfor shared state; useloomfor model-checking critical sections
Implementation
- Run all commands through the pinned-toolchain wrapper script (e.g.
scripts/with-pinned-rust.sh cargo ...) - Every new crate must include
[lints] workspace = truein itsCargo.toml - Style: inline format args (
format!("{x}")), method refs over closures (.map(String::as_str)), explicit match arms over wildcards, collapse nested ifs - No
println!/eprintln!for operational output — usetracingevents - No
.unwrap()or.expect()in library code; in binary code, only at startup with a clear message unsafeblocks: add// SAFETY:comment explaining invariants, add local#[allow(unsafe_code)], document in PR- Adding a dependency: add to
[workspace.dependencies]first, reference with{ workspace = true }, then runcargo deny checkandcargo machete
Testing
- Unit tests in
#[cfg(test)]modules within the source file - Integration tests in
tests/integration/; contract/E2E tests in separate crates - Use
proptestfor property-based testing of pure functions and data invariants - Use
loomfor model-checking concurrent code (mutex invariants, atomic correctness) - Use
rstestfor parameterized test cases - Use
instafor snapshot testing of complex outputs - Use
testcontainersfor tests requiring real external services (databases, message queues) - Use
tempfilefor filesystem fixtures; never hard-code paths - Run focused tests first:
cargo test -p <crate> <test_name>, then full suite - Coverage:
cargo llvm-covfor source-line coverage gating
Quality Gates (pre-commit / CI)
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --no-deps -- -D warnings -D clippy::todo -D clippy::unimplemented -D clippy::dbg_macro -D clippy::print_stdout -D clippy::unwrap_usedcargo deny checkcargo machete crates tools(or workspace equivalent)cargo test --workspace(excluding infra-dependent suites in pure-unit CI)
Performance
- Benchmark with
criterion(statistical) or a custom bench harness - Profile with
[profile.profiling]+cargo flamegraphorpprof - Do not claim performance improvements without exact benchmark command and output
- Local storage/throughput targets take precedence over remote-tier optimizations until explicitly promoted
Innsigle seal: model-primary by HELIX
The signature covers the markdown source of this page, not these HTML bytes. This page quotes that seal; verify it against the source file.
- Composition
- model-primary
- Issuer
- HELIX
helix - Signing key
ed25519:b0865d76d834a52c48506414d16f4e5a(build key)- Signed source
concerns/rust-cargo.md- Signed
- 2026-09-23T14:11:58Z
- Content digest
sha256:7016d6cf…f9897795
This build key is endorsed by the human key for build signing; the signature is not a detector and not a truth guarantee.
Raw attestation JSON
{
"payload": {
"innsigle": "1",
"type": "https://innsigle.dev/claim/colophon/v1",
"issued_at": "2026-09-23T14:11:58Z",
"issuer": {
"id": "helix",
"name": "HELIX",
"key_id": "ed25519:b0865d76d834a52c48506414d16f4e5a",
"key_url": "https://documentdrivendx.github.io/helix/.well-known/innsigle/keys.json"
},
"subjects": [
{
"uri": "https://documentdrivendx.github.io/helix/concerns/rust-cargo/",
"digest": {
"alg": "sha256",
"value": "7016d6cf3e6864aa49fa10e5d03fd9ce3065779b13418317a007ee38f9897795"
}
}
],
"colophon": {
"schema_version": "1",
"composition": "model-primary",
"ingredients": [
{
"kind": "model",
"name": "Claude",
"role": "draft"
},
{
"kind": "tool",
"name": "sloptimizer",
"role": "rewrite"
},
{
"kind": "human",
"name": "operator",
"role": "structure-edit"
}
],
"notes": null
}
},
"payload_encoding": "json",
"signatures": [
{
"key_id": "ed25519:b0865d76d834a52c48506414d16f4e5a",
"alg": "ed25519",
"sig": "LGVr0tLedTpzRoEvxqxMU6L90lIsuQNyjip7wqrEOLFjol7giw6nX-7N5kASHJ0kp0bj4ScYZ9ZomNr0C5RTCA",
"signed_at": "2026-09-23T14:11:58Z"
}
]
}