LANGUAGE » RUST

Cargo

Usage

Rust's package manager.

shell
cargo OPTIONS COMMAND
CommandDescription
newCreate a new Cargo package.
addAdd dependencies to a manifest file.
removeRemove dependencies from a manifest file.
buildCompile the current package.
runBuild if not compiled, generate a binary and run.
testRun the tests.
updateUpdate dependencies in the Cargo.lock file.
shell
cargo new myproject
cd myproject
cargo add iced
# Create your script...
cargo run

More details on cargo update and Cargo.tomlhere.

Release builds

Strip on releases to get smaller binaries by adding to Cargo.toml:

toml
[profile.release]
strip = "symbols"

Further optimizations can be done with lto and codegen-units.

toml
[profile.release]
codegen-units = 1
lto = "fat"

Build the binary:

shell
cargo build --release

Tests

Create a directory named tests:

txt
myproject
├── Cargo.toml
├── src
│   └── main.rs
│   └── lib.rs
└── tests
    ├── my_test.rs
    └── my_other_test.rs

Run a subset of the tests with by using a pattern.

shell
cargo test PATTERN