Cargo
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 testBacktrace
To backtrace set the RUST_BACKTRACE environment variable:
RUST_BACKTRACE=1 cargo runThreads
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=1Show output for passing tests as well as failed tests
cargo test -- --show-outputPass test name to cargo (this equals test function name)
cargo test one_hundredRun ignored tests
cargo test -- --ignoredFix
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 src_shell{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 buildbuild
cargo build --releaseDocumentation
See [Rust Comments](Rust Comments) for documentation syntax.
Generation
cargo docOpen in browser
cargo doc --open