agentleFS
botirkhaltaevbotirkhaltaev/botir-skills/skills/rust-cargo-mastery/SKILL.md

rust-cargo-mastery

Skill4 starsChanged 3 months agoApache-2.0View on GitHub

Master Cargo, the Rust package manager. Use when managing dependencies, configuring builds, setting up workspaces, publishing crates, using features for conditional compilation, or optimizing build times.

Files
SKILL.md

Rust Cargo Mastery

Comprehensive guide to Cargo based on The Cargo Book.

When to Use This Skill

  • Setting up new Rust projects
  • Managing dependencies from crates.io
  • Configuring build profiles and features
  • Working with Cargo workspaces
  • Publishing crates to crates.io
  • Optimizing build times
  • Understanding Cargo's resolution algorithm

Core References

Dependencies

Specifying Dependencies

[dependencies]
serde = "1.0"           # Exact or semver range
regex = "1.5"            # Minor version compatible
anyhow = "1.0"          # Any 1.x version
rand = { version = "0.8", features = ["small_rng"] }

[dev-dependencies]
criterion = "0.5"

Version Syntax

SyntaxMeaning
"1.0">=1.0.0, <2.0.0
"=1.0.0"Exact version
"^1.0">=1.0.0, <2.0.0
"~1.0">=1.0.0, <1.1.0

External Dependencies

[dependencies]
log = "0.4"
env_logger = { path = "../env_logger" }
my_crate = { git = "https://github.com/user/repo" }

Workspaces

Basic Workspace

# Cargo.toml (workspace root)
[workspace]
members = ["crate_a", "crate_b"]
resolver = "2"

[workspace.package]
version = "1.0.0"
edition = "2021"

[workspace.dependencies]
serde = "1.0"
# crate_a/Cargo.toml
[package]
name = "crate_a"
version.workspace = true
edition.workspace = true

[dependencies]
serde = { workspace = true }

Workspace Features

[workspace]
members = ["lib", "binary"]

[workspace.dependencies]
my_lib = { path = "lib", default-features = false }

Features

Defining Features

[features]
default = ["std"]
std = []
derive = ["serde/derive"]
experimental = []

Feature Unification

Workspace dependencies use unified features:

[dependencies]
common = { path = "../common", features = ["derive"] }
# Uses common's "derive" feature automatically

Conditional Compilation

#[cfg(feature = "experimental")]
fn experimental_api() {}

#[cfg(not(feature = "std"))]
fn no_std_compatible() {}

Build Profiles

Custom Profiles

[profile.dev]
opt-level = 0
debug = true
split-debuginfo = "unpacked"

[profile.release]
opt-level = 3
lto = "thin"
codegen-units = 1

[profile.bench]
inherits = "release"

Profile Override

[profile.dev.package."*"]
opt-level = 2

Publishing

Publishing to crates.io

cargo login
cargo publish

Package Metadata

[package]
name = "my_crate"
version = "1.0.0"
edition = "2021"
description = "A short description"
license = "MIT"
license-file = "LICENSE"
repository = "https://github.com/user/repo"
documentation = "https://docs.rs/my_crate/"
homepage = "https://mycrate.io"
keywords = ["tag1", "tag2"]
categories = ["category1", "category2"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

Reference Map

  • references/dependencies.md - Dependency specification, versions
  • references/workspaces.md - Workspace configuration
  • references/features.md - Feature flags, conditional compilation
  • references/profiles.md - Build profiles, optimization
  • references/publishing.md - Publishing to crates.io

Common Commands

cargo new project_name
cargo build
cargo run
cargo test
cargo check
cargo doc
cargo publish
cargo update
cargo tree
cargo clippy

Key References

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.