Rust and Cargo 1 cheatsheet

Rust and Cargo 1: Projects and toolchain

8 common Rust and Cargo 1 tasks.

Check the Rust version

Print the installed compiler version.

rustc --version

Update Rust

Update the installed toolchains to their latest releases.

rustup update

Create a new binary project

Create a project with a main.rs and a Cargo.toml.

cargo new my-app

Create a new library

Create a library crate with a lib.rs.

cargo new my-lib --lib

Initialize Cargo in the current folder

Turn an existing folder into a Cargo package.

cargo init

Add a compilation target

Install the standard library for another target, here WebAssembly.

rustup target add wasm32-unknown-unknown

Install clippy and rustfmt

Add the linter and formatter to the active toolchain.

rustup component add clippy rustfmt

Install the nightly toolchain

Install a toolchain for unstable features, then run with cargo +nightly.

rustup toolchain install nightly

Was this page helpful?