{{~*set command=“run”}} {{~*set actionverb=“Run”}}
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 {{man “cargo-test” 1}} and {{man “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.
{{> section-options-package }}
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.
{{#option “--bin
name” }} Run the specified binary. {{/option}}
{{#option “--example
name” }} Run the specified example. {{/option}}
{{/options}}
{{> section-features }}
{{> options-target-triple }}
{{> options-release }}
{{> options-profile }}
{{> options-ignore-rust-version }}
{{> options-timings }}
{{/options}}
{} {{> options-target-dir }} {{/options}}
{{> options-display }}
{{> options-message-format }}
{{/options}}
{{> options-manifest-path }}
{{> options-locked }}
{{/options}}
{{> section-options-common }}
{} {{> options-jobs }} {{> options-keep-going }} {{/options}}
{{> section-environment }}
{{> section-exit-status }}
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
{{man “cargo” 1}}, {{man “cargo-build” 1}}