Guide for managing Cargo dependencies using cargo CLI commands instead of manually editing Cargo.toml. Use this skill when working on Rust projects that need dependency management.
This skill ensures dependencies are always added to Rust projects using cargo add CLI commands rather than manually editing Cargo.toml. This guarantees the latest compatible versions are used and maintains proper dependency resolution.
NEVER manually edit Cargo.toml to add dependencies. Always use:
cargo add crate_name
With features:
cargo add crate_name --features "feature1,feature2"
Dev dependencies:
cargo add crate_name --dev
Build dependencies:
cargo add crate_name --build
With version constraint (only when necessary):
cargo add crate_name --version "^1.0.0"
Use cargo remove instead of manually deleting from Cargo.toml:
cargo remove crate_name
cargo remove crate_name --dev
cargo remove crate_name --build
Use cargo upgrade to update dependencies (requires cargo-edit package):
cargo upgrade crate_name
cargo upgrade --all
cargo upgrade --dry-run
cargo tree
cargo outdated
Use this skill whenever you need to:
cargo add - Never hardcode versions unless explicitly required--features flagcargo tree after adding to verify transitive dependenciescargo build and cargo test after dependency changes--dry-run flag to preview changes