Rust and C++ Tooling Equivalencies

This is a cheat sheet for you to refer to later.

Using Cargo

The cargo command is a swiss-army knife that handles building projects, testing them, controlling dependencies and more. It is extensible, you can add more features to it and use it to install programs.

Cargo CommandC++ EquivalentPurpose
Package Commands
cargo init
Compilation
cargo buildmakeBuilds your project, placing the output in the target directory.
cargo runmake ; ./my_programRuns cargo build, and then runs the resulting executable.
cargo checkBuild only the source, and skip assembly and linking for a quick check of syntax.
cargo cleanmake cleanRemoves all build artefacts and empties the target directory.
cargo rustcPass extra rustc commands to the build process
Formatting
cargo fmtFormats your source code according to the Rust defaults.
Testing
cargo testmake testExecutes all unit tests in the current project
cargo benchExecutes all benchmarks in the current project.
Linting
cargo clippyRuns the Clippy linter
cargo fixApplies all Clippy suggestions
Documentation
cargo docBuilds a documentation website from the current project's sourcecode.
cargo rustdocRun the documentation builder with extra command options.
Dependencies
cargo fetchDownloads all dependencies listed in Cargo.toml from the Internet.
cargo addAdd a dependency to the current project's Cargo.toml
cargo removeRemove a dependency from the current project's Cargo.toml file
cargo updateUpdate dependencies to the latest version in Cargo.toml
cargo treeDraw a tree displaying all dependencies, and each dependency's dependencies
cargo vendorDownload all dependencies, and provide instructions to modify your Cargo.toml to use the downloaded dependencies.