Rust reference

Operational lookup companion to the Rust ecosystem architecture: toolchains, Cargo structure, dependency resolution, features, profiles, targets, build gates, publication, and graph inspection. Current to Rust 1.98.0, snapshot 2026-09-03.

Toolchains, channels, and components

CommandPurposeArchitecture note
rustup showShow active/default toolchains, installed targets, and overridesFirst diagnostic when Cargo and the editor disagree
rustup update stableUpdate the stable channel and installed componentsCurrent snapshot: 1.98.0
rustup toolchain install 1.98.0Install an exact archived toolchainUseful for reproducing a historical build
rustup override set stableSet a directory overrideA committed rust-toolchain.toml is visible to every checkout
rustup component add clippy rustfmtAdd optional toolchain componentsAvailability can differ by toolchain and host
rustup target add <triple>Install a target standard libraryDoes not install the target linker, SDK, or native libraries
cargo +nightly ...Run a Cargo command through the nightly proxyPin dated nightly when a build depends on unstable behavior

rustup command surface. Toolchain selection precedes Cargo resolution: the selected Cargo and rustc versions can change accepted manifests, resolver behavior, diagnostics, and artifacts. Sources: The rustup book: Toolchains; The rustup book: Components; The rustup book: Cross-compilation.

# rust-toolchain.toml — pin what CI and local proxies select.
[toolchain]
channel = "1.98.0"
profile = "minimal"
components = ["clippy", "rustfmt"]
targets = ["wasm32-unknown-unknown"]

The stable channel is the deployment default for most projects. Beta tests the next release; nightly exposes unstable compiler and Cargo features and may occasionally lack optional components. Treat a nightly date as a dependency when it is required by a build.

Back to top

Project anatomy

TermIdentityWhat it controls
WorkspaceOne or more packages managed togetherRoot Cargo.toml, one Cargo.lock, shared target/
PackageVersioned and publishable unitOne Cargo.toml; contains one or more targets
TargetA buildable library, binary, example, test, or benchmarkEvery target compiles as a crate
CrateOne compilation unit and trait-coherence boundaryRooted at lib.rs, main.rs, or an explicit path
ModuleName and privacy hierarchy within a crateInline or loaded from another source file
FeatureAdditive conditional capability of a packageAffects dependency and cfg activation
ProfileCompiler settings for a kind of builddev, release, test, bench, or custom
Target tripleArchitecture-vendor-OS-environment output contractSelects cfg, ABI, libraries, and linker

The package-model vocabulary. In particular, package and crate are not synonyms. Source: The Cargo Book: Glossary; The Cargo Book: Workspaces.

workspace/
├── Cargo.toml          # [workspace], shared dependencies/lints/profiles
├── Cargo.lock          # concrete resolution for the workspace
├── rust-toolchain.toml # compiler/tool selection (rustup)
├── crates/
│   ├── domain/         # library package: stable application concepts
│   ├── adapters/       # library package: DB/network integrations
│   └── service/        # binary package: composition root
└── .cargo/config.toml  # target/linker/build environment policy

Keep dependency direction visible: domain packages should not need transport, database, or runtime adapters. The binary package is usually the composition root that selects implementations and operational policy. This is an architectural convention, not a rule Cargo infers.

Back to top

Manifest and workspace keys

TableCarriesBoundary
[package]name, version, edition, rust-version, licence, repository, publish policyPackage identity and compatibility declaration
[dependencies]normal target dependenciesEnter library/binary artifacts
[dev-dependencies]tests, examples, benchmarksIgnored when this package is a dependency
[build-dependencies]dependencies of build.rsCompile and execute for the host
[target.'cfg(...)'.dependencies]target-conditional graph edgesResolver considers target conditions; activation differs by resolver/build
[features]named additive cfg/dependency activationPublic API and build-matrix surface
[lib], [[bin]]target paths, names, crate typesCompilation and linkage units
[workspace]members, resolver, shared metadata/dependencies/lintsPolicy at repository/package-graph scope
[profile.*]optimization, debug info, panic, LTO, codegen unitsArtifact behavior and cost
[lints]rustc and Clippy levels/prioritiesVersioned quality policy

High-impact stable Cargo.toml tables. Source: The Cargo Book: The Manifest Format; The Cargo Book: Workspaces; The Cargo Book: Lints.

[workspace]
members = ["crates/domain", "crates/adapters", "crates/service"]
resolver = "3"

[workspace.package]
edition = "2024"
rust-version = "1.85"
license = "MIT OR Apache-2.0"

[workspace.dependencies]
serde = { version = "1", features = ["derive"] }

[workspace.lints.rust]
unsafe_code = "forbid"

[profile.release]
lto = "thin"
panic = "abort"

Workspace inheritance centralizes a constraint; it does not automatically make every dependency public to every member. A member still opts in with dependency.workspace = true. Profile sections are read from the workspace root. A virtual workspace has no root package edition from which to infer a resolver, so declare it explicitly.

Back to top

Dependencies, features, and resolution

MechanismMeaningDesign consequence
Version requirementAllowed releases, commonly caret compatibilityIntent in Cargo.toml
Resolved package IDName + exact version + sourceConcrete node in Cargo.lock/metadata
Default featuresEnabled unless default-features = falsePart of a crate's default architecture
Optional dependencyActivated by a featureStill an additive graph capability
Feature unificationUnion within the active resolver boundaryA dependency is not built once per caller
Resolver 2Separates some target/build/dev feature activationDefault for edition 2021
Resolver 3Adds MSRV-aware incompatible-version fallbackDefault for edition 2024; Rust 1.84+
[patch]Registry/source overlay selected at workspace rootTesting or replacing a dependency source

Cargo dependency-resolution concepts. Sources: The Cargo Book: Dependency Resolution; The Cargo Book: Features; The Cargo Book: Workspaces.

[features]
default = ["tls-rustls"]
tls-rustls = ["dep:rustls"]
metrics = ["dep:metrics"]

[dependencies]
rustls = { version = "0.23", optional = true }
metrics = { version = "0.24", optional = true }

Features should be additive: enabling two callers’ feature sets must not silently select incompatible global modes. If two backends are mutually exclusive, prefer separate adapter crates, an explicit runtime constructor, or a build error that makes the illegal combination visible. Test default, no-default, all, and supported feature combinations rather than assuming one successful build covers the graph.

cargo tree --workspace --target all --all-features
cargo tree -e features
cargo tree -d                       # duplicate package versions
cargo metadata --format-version 1   # machine-readable resolved graph
cargo update -p package --precise 1.2.3

Back to top

Build, test, lint, and documentation commands

CommandWhat it establishesLimit
cargo check --workspace --all-targetsType-check without final code generationFast structural gate; does not prove linking or runtime behavior
cargo build --lockedBuild without changing Cargo.lockCI/release lock discipline
cargo test --workspaceUnit, integration, and documentation testsBuilds test harnesses
cargo fmt --all -- --checkCheck rustfmt outputTextual consistency gate
cargo clippy --all-targets --all-features -- -D warningsCompiler-integrated lintsFeature-complete lint gate; may expose combinations not shipped
cargo doc --no-deps --document-private-itemsGenerate API documentationUseful for reviewing module and public/private structure
cargo fixApply machine-applicable compiler suggestionsReview the resulting diff
cargo benchRun benchmark targetsStable statistical harness usually comes from a crate
cargo miri testInterpret tests under MiriAdditional UB checking; not a general executor

A layered local/CI gate. No one command establishes correctness, portability, soundness, or supply-chain trust. Sources: The Cargo Book: Commands; The Cargo Book: cargo test; The Cargo Book: cargo doc; Rust tools; Miri.

Integration tests under tests/ compile as separate crates and exercise only public API. Unit tests inside modules can reach private items. Documentation tests keep examples executable. Cross-target tests need a runner or deployment environment; compiling for another target is not the same as executing there.

Back to top

Profiles, artifacts, and reproducibility

Setting/profileRoleTradeoff
devopt-level 0, debug assertions on, overflow checks onFast edit/build loop
releaseopt-level 3, debug assertions off, overflow checks offDeployment baseline; tune explicitly
testInherits devTest harness and dependencies
benchInherits releaseBenchmark targets
ltooff, thin, fat, or linker-pluginCross-unit optimization versus link time
codegen-unitsPartitions code generationParallel compile speed versus optimization opportunity
panicunwind or abortBinary size and cleanup/unwind behavior
strip / debugSymbol retention and debug-info levelArtifact size versus postmortem diagnosis

Cargo profile controls with architecture impact. Defaults can evolve; inspect the linked reference for the selected toolchain. Source: The Cargo Book: Profiles; The Cargo Book: Build Cache.

--locked refuses lockfile changes. --offline refuses network access. --frozen requests both. They constrain Cargo’s inputs but do not by themselves make every build bit-for-bit reproducible: native toolchains, environment variables, paths, timestamps, build scripts, and linker behavior may still vary. Preserve the toolchain file, lockfile, target, native dependencies, and build environment as one release input.

The target directory contains final and intermediate artifacts, fingerprints, incremental caches, build- script outputs, generated docs, and package archives. With --target, host build scripts and proc macros are separated from target artifacts. Do not treat paths inside the internal build directory as a stable API; consume declared outputs and Cargo metadata instead.

Back to top

Targets, no_std, linking, and FFI

Deployment shapeLibrary/runtime boundaryTypical artifact
Hosted nativestd + target runtime/ABIbin, rlib, dylib, cdylib, staticlib
no_std + alloccore plus allocator-backed collectionsKernel, firmware, constrained runtime
no_std + coreNo allocation or OS assumptionBare-metal or highly constrained target
WebAssemblyTarget std/core plus host importswasm module, often with generated host glue
C ABIextern declarations and repr(C) datastaticlib/cdylib or native dependency
Python extensionPyO3 and Python runtime contractcdylib packaged as a Python module
C++ bridgeCXX-generated bridge plus C++ toolchainLinked native library/binary

Deployment shapes and their explicit runtime boundary. Sources: rustc Platform Support; The rustup book: Cross-compilation; The Embedded Rust Book: no_std; The Rustonomicon: FFI; PyO3 user guide; CXX Rust/C++ interop; The wasm-bindgen Guide.

# Show target facts from the selected compiler.
rustc --print target-list
rustc --print cfg --target x86_64-unknown-linux-gnu

# Install Rust's target library, then provide the required linker/SDK separately.
rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown

#[repr(C)] requests a C-compatible representation for supported types; it does not make Rust strings, vectors, trait objects, enums with data, or panics into portable C APIs. Prefer opaque handles, fixed-width scalars, explicit byte spans, paired allocation/free functions, and status/error values. State which side owns every allocation and never unwind through a foreign ABI that does not permit it.

Back to top

Publication and compatibility

CommandEffectBoundary
cargo package --listInspect files selected for the crate archiveRun before publication
cargo packageCreate and verify a local .crate archiveExercises packaged, not checkout, inputs
cargo publish --dry-runRun publication checks without uploadDoes not reserve the version
cargo publishUpload an immutable version to the selected registryOwnership/token required
cargo yank --version XPrevent new resolutions from selecting a versionDoes not delete it or break locks

Cargo publication lifecycle. crates.io is designed as a permanent archive: yanking changes future resolution, not existing locked builds. Source: The Cargo Book: Publishing on crates.io; The Cargo Book: Registry Index.

Cargo’s SemVer guidance treats more changes as breaking than signature comparison alone suggests: removing public items, tightening generic bounds, adding trait requirements, changing feature behavior, or exposing new trait implementations can affect downstream type inference and coherence. Run downstream tests and inspect public API diffs, but keep the human compatibility contract explicit. The rust-version field declares the minimum supported Rust version; testing it remains the publisher’s responsibility. Source: The Cargo Book: SemVer Compatibility; The Cargo Book: The Manifest Format.

Back to top

Inspection and assurance workflow

QuestionMechanismEvidence produced
Resolved topologycargo metadata; cargo treePackages, sources, targets, features, duplicate versions
Build executionbuild.rs/proc-macro inventoryWhich dependencies run on the host and why
Unsafe boundarylint plus code/invariant reviewWhere compiler obligations become human obligations
Advisoriescargo audit / RustSecKnown vulnerable or unmaintained package records
Policycargo denyAllowed licences, sources, bans, duplicates, advisories
Review evidencecargo vetAudits and trusted imports for dependency criteria
Dynamic behaviortests, sanitizers where applicable, MiriExecuted paths under distinct models
Performancecriterion plus workload/system measurementsRegression distributions and operational cost

Review layers for a Rust dependency graph. Each answers a different question; passing one is not evidence for the others. Sources: The Cargo Book: cargo metadata; The Cargo Book: Build Scripts; The Rustonomicon: Working with Unsafe; RustSec Advisory Database; cargo-deny documentation; cargo-vet documentation; Miri; Criterion.rs documentation.

# A compact release gate; add target- and project-specific jobs around it.
cargo fmt --all -- --check
cargo check --workspace --all-targets --locked
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo test --workspace --locked
cargo doc --workspace --no-deps
cargo tree -d

A deep review records exceptions: why a duplicate version remains, which native toolchain is trusted, which unsafe invariant was checked, which features are intentionally excluded, and which targets were compiled versus executed. The command transcript is evidence only when paired with the exact toolchain, lock graph, target, and configuration that produced it.

Back to top

Sources

Official Rust and Cargo documentation defines the toolchain. Project-owned documentation defines each optional ecosystem tool. Snapshot date: 2026-09-03.

  1. The rustup book: Toolchains, The Rust Project.
  2. The rustup book: Components, The Rust Project.
  3. The rustup book: Cross-compilation, The Rust Project.
  4. The Cargo Book: Glossary, The Rust Project.
  5. The Cargo Book: The Manifest Format, The Rust Project.
  6. The Cargo Book: Workspaces, The Rust Project.
  7. The Cargo Book: Dependency Resolution, The Rust Project.
  8. The Cargo Book: Features, The Rust Project.
  9. The Cargo Book: Profiles, The Rust Project.
  10. The Cargo Book: Build Cache, The Rust Project.
  11. The Cargo Book: Commands, The Rust Project.
  12. The Cargo Book: cargo test, The Rust Project.
  13. The Cargo Book: cargo doc, The Rust Project.
  14. The Cargo Book: Publishing on crates.io, The Rust Project.
  15. The Cargo Book: Registry Index, The Rust Project.
  16. The Cargo Book: SemVer Compatibility, The Rust Project.
  17. The Cargo Book: Lints, The Rust Project.
  18. The Cargo Book: cargo metadata, The Rust Project.
  19. Rust tools, The Rust Project.
  20. Miri, The Rust Project.
  21. rustc Platform Support, The Rust Project.
  22. The Embedded Rust Book: no_std, The Rust Project.
  23. The Rustonomicon: FFI, The Rust Project.
  24. The Rustonomicon: Working with Unsafe, The Rust Project.
  25. PyO3 user guide, PyO3 project.
  26. CXX Rust/C++ interop, CXX project.
  27. The wasm-bindgen Guide, wasm-bindgen project.
  28. RustSec Advisory Database, RustSec.
  29. cargo-deny documentation, Embark Studios.
  30. cargo-vet documentation, Mozilla.
  31. Criterion.rs documentation, Criterion project.

Back to top