cargo-run
Run the Rust project's main executable
TLDR
Run the default binary target
Run the specified binary
Run the specified example
Activate a space or comma separated list of features
Disable the default features
Activate all available features
Run with the given profile
SYNOPSIS
cargo run [OPTIONS] [--] [<ARGS>...]
PARAMETERS
--bin <NAME>
Build and run the specified binary.
--example <NAME>
Build and run the specified example.
--test <NAME>
Build and run the specified integration test.
--bench <NAME>
Build and run the specified benchmark.
-p SPEC, --package SPEC
Package to build and run.
--release, -r
Build in release (optimized) mode.
--target TRIPLE
Target platform triple.
--manifest-path PATH
Path to Cargo.toml.
--jobs N
Number of parallel jobs.
-v, --verbose
Verbose output.
-q, --quiet
No output except errors.
--frozen
No update to Cargo.lock.
--locked
Use Cargo.lock as-is.
--offline
Offline mode, no network.
-h, --help
Print help.
--version, -V
Print version.
DESCRIPTION
The cargo run command is a core subcommand of Cargo, Rust's build system and package manager. It automatically builds the current package in the current directory (or specified target) and then executes the resulting binary.
By default, it compiles and runs the binary in debug mode, which is suitable for development and testing. This command is especially useful during development as it saves the step of manually invoking cargo build followed by executing the binary.
It supports running specific binaries, examples, tests, or benches from the workspace. Arguments passed after -- are forwarded to the executed binary. Cargo tracks dependencies and rebuilds only what's necessary for efficiency.
Common use cases include quick iteration on command-line tools, web servers, or scripts. For production, pair it with --release for optimizations. It respects Cargo.toml configurations like [[bin]] sections.
CAVEATS
By default uses debug mode (slow); use --release for speed. Does not work with proc-macros or cdylib crates. Arguments after -- go to binary, not Cargo.
EXAMPLES
cargo run -- hello
cargo run --release -- --help
cargo run --example hello_utils
EXIT STATUS
0 on success; 101 if binary panics; inherits binary's exit code otherwise.
HISTORY
Introduced in Cargo 0.0.1 (2014) by Mozilla's Rust team. Evolved with Cargo's stabilization in Rust 1.0 (2015). Key enhancements in Cargo 1.0+ include workspace support and better incremental builds.


