cargo-run --- Run the current package
cargo run
[options] [--
args]
Run a binary or example of the local package.
All the arguments following the two dashes (--
) are passed to the binary to run. If you're passing arguments to both Cargo and the binary, the ones after --
go to the binary, the ones before go to Cargo.
Unlike cargo-test(1) and cargo-bench(1), cargo run
sets the working directory of the binary executed to the current working directory, same as if it was executed in the shell directly.
By default, the package in the current working directory is selected. The -p
flag can be used to choose a different package in a workspace.
When no target selection options are given, cargo run
will run the binary target. If there are multiple binary targets, you must pass a target flag to choose one. Or, the default-run
field may be specified in the [package]
section of Cargo.toml
to choose the name of the binary to run by default.
The feature flags allow you to control which features are enabled. When no feature options are given, the default
feature is activated for every selected package.
See the features documentation for more details.
See the reference for details on environment variables that Cargo reads.
0
: Cargo succeeded.101
: Cargo failed to complete.Build the local package and run its main target (assuming only one binary):
cargo run
Run an example with extra arguments:
cargo run --example exname -- --exoption exarg1 exarg2