Description
Cargo is Rust’s build system and package manager.
Configuration
Commands
Create project
cargo new hello_cargoBuild & run project
cargo runBacktrace
When you want to see an error backtrace set the RUST_BACKTRACE
environment variable:
RUST_BACKTRACE=1 cargo runPublish to Crates.io
cargo publishInstall package
cargo install ripgrepLinting & testing
Check code
cargo checkTesting
cargo test-
Backtrace
To backtrace set the
RUST_BACKTRACEenvironment variable:RUST_BACKTRACE=1 cargo run -
Threads
By default cargo runs test in parallel. For more control over this you can pass the number of threads you want to use. For example to only use 1 thread:
cargo test -- --test=threads=1 -
Show output for passing tests as well as failed tests
cargo test -- --show-output -
Pass test name to cargo (this equals test function name)
cargo test one_hundred -
Run ignored tests
cargo test -- --ignored
Fix
The rustfix tool is included with Rust installations and can automatically fix some compiler warnings.
cargo fixBuilds
Profiles
In Rust, release profiles are predefined and customizable profiles with different configurations that allow a programmer to have more control over various options for compiling code. Each profile is configured independently of the others.
Cargo has two main profiles: the dev profile Cargo uses when you run
cargo build and the release profile Cargo uses when you run
cargo build --release. The dev profile is defined with good defaults
for development, and the release profile has good defaults for release
builds.
-
dev
cargo build -
build
cargo build --release
Documentation
See Rust Comments for documentation syntax.
Generation
cargo docOpen in browser
cargo doc --open