Linux command
cargo-run 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Build and run project
cargo run
Run with release optimizations
cargo run --release
Run specific binary
cargo run --bin [binary_name]
Run example
cargo run --example [example_name]
Pass arguments to binary
cargo run -- [arg1] [arg2]
Run with features enabled
cargo run --features [feature1,feature2]
Run specific package
cargo run -p [package]
说明
cargo run builds and executes a binary target of the current package. It automatically recompiles the project when source files have changed, then runs the resulting executable. Any arguments placed after `--` are forwarded directly to the binary rather than being interpreted by Cargo. If the package contains multiple binary targets, a specific one must be selected with `--bin` or `--example`, or a default can be configured via the `default-run` field in Cargo.toml. The binary's working directory is set to the current shell directory.
参数
- --bin _name_
- Run specified binary
- --example _name_
- Run specified example
- -r, --release
- Run with release profile optimizations
- --profile _name_
- Build with specific profile
- -p, --package _spec_
- Run from specified package
- --target _triple_
- Run for target platform
- -j, --jobs _n_
- Parallel build jobs
- --features _features_
- Enable specified features
- --all-features
- Enable all features
- --no-default-features
- Disable default features
- -v, --verbose
- Verbose output
FAQ
What is the cargo-run command used for?
cargo run builds and executes a binary target of the current package. It automatically recompiles the project when source files have changed, then runs the resulting executable. Any arguments placed after `--` are forwarded directly to the binary rather than being interpreted by Cargo. If the package contains multiple binary targets, a specific one must be selected with `--bin` or `--example`, or a default can be configured via the `default-run` field in Cargo.toml. The binary's working directory is set to the current shell directory.
How do I run a basic cargo-run example?
Run `cargo run` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --bin _name_ do in cargo-run?
Run specified binary