- Create SMALL rust binaries, see: min-sized-rust.
- Compile simple programs w/
rustc
, but larger programs w/cargo
. - Format your code automatically:
rustfmt
.
-
Creates a new crate (it's like
go mod init
):cargo new <name>
Without a git repository:
cargo new <name> --vcs none
-
Build the crate (it's like
go create
):cargo build
cargo b
-
Run the crate (it's like
go run
):cargo run
cargo r
- Silently run:
cargo r -q
-
Check whether your program can compile:
cargo check
cargo c
Rustaceans use this command to periodically check their programs. After working on their program, and when they're sure, they build your program using
cargo build --release
.This command produces a faster program, but it'll take a longer time to compile.
This is also the command you want to use when you benchmark your code.
-
Cargo caches. If you want to start on a clean slate, run:
cargo clean
Why? Sometimes,
cargo check
returns a warning. However, when you run it the second time, it doesn't display the warning. In that case, you can runcargo clean
, and then runcargo check
again. This way, you'll be able to see the error message again. -
You can see the documentation of every crate that your program/package depends on.
cargo doc --open
-
Create a library package.
cargo new --lib <name>
This command will create a package with a test.
-
Work on someone else's project:
git clone url/project cd project cargo build
- Use Valgrind to check for memory errors.