cargo fmt (built-in) formats your code. cargo clippy (built-in) lints your code. cargo-spellcheck⮳ checks for spelling errors.
Dependency Management
cargo-update⮳ updates dependencies as recorded in the local lock file (built-in). cargo tree (built-in) displays your dependency tree. Use -d to list crates where more than one version is getting pulled in and what's pulling each version in. cargo-outdated⮳ lists packages that have newer versions than what your Cargo.toml and Cargo.lock are pinning. cargo add adds dependencies to your Cargo.toml. cargo rm removes dependencies. cargo-edit⮳ edits your Cargo.toml file. It adds cargo add <dependency>, cargo rm <dependency> and cargo upgrade to update your Cargo.toml's versions. This functionality is planned to be part of Cargo itself.
Testing/Benchmarking
cargo test (built-in) runs your tests (built-in, but often considered a plugin). cargo bench (built-in) runs your benchmarks. cargo fuzz or cargo-afl⮳ run your fuzz tests.
Use cargo-asm⮳ to investigate what the compiler generates from your code. cargo-expand⮳ shows the expanded output from macros. cargo-modules⮳ renders a tree or Graphviz graph of the modules within a crate.
Security
cargo-audit⮳ checks whether any of your dependencies are of a version that has a security advisory out against them. cargo-geiger⮳ identifies dependencies with unsafe code, so you can either audit them or find alternatives.
cargo-bloat⮳ identifies what's contributing to your binary's size (eg. modules with generic functions or macros not designed with size-efficiency in mind).
Publishing, Distribution
cargo publish publishes your crate to crates.io (built-in). cargo-deb⮳ creates Debian packages. cargo-rpm⮳ creates RPM packages.
Change Watching
cargo-watch⮳ watches your project for changes and rebuilds / re-run a command every time the source changes (e.g. cargo test).
Cargo plugins are essentially just executables that follow a certain naming convention (i.e. cargo-something). To create a Cargo Plugin, create a regular Rust project (often a binary crate) and name the executable cargo-<your name here>. Cargo will automatically discover and run these executables.
| Argument Parsing | Use clap⮳, structopt⮳, argh⮳ for parsing command-line arguments passed to the plugin. |
| Working with Cargo | Interact with Cargo.toml or other Cargo metadata. serde⮳ is often used for parsing TOML or JSON. |
| Filesystem Operations | Use std::fs, pathdiff⮳. |
| Process Management | Use std::process for running External Commands. |
| Networking, HTTP Client (if needed) | Use reqwest⮳, hyper⮳. |
| Serialization/Deserialization | Use serde⮳ for handling configuration or data. |
| Logging | Use tracing, orlog⮳ and env_logger⮳. |
There is an unstable Cargo API, but it's not recommended for most plugins due to its instability.