Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Getting Started

Installation

Rustup: the Rust installer and version management tool

# check installation
rustc --version
cargo --version
# or
rustc -V
cargo -V

# update rust
rustup update

# uninstall rust
rustup self uninstall

# open local doc
rustup docs --book

Untitled

Untitled

Untitled

Development Environment

  • VS Code + (plugin: rust-analyzer) 👍
  • RustRover (by JetBrains)

Hello World!

hello_world.rs

fn main() {
    println!("Hello, world!");
}

rustc

# compile
rustc ./hello_world.rs

# run
./hello_world

# windows
.\hello_world.exe

Package Management

Cargo: the Rust build tool and package manager

cargo --version

cargo new hello_cargo
# init without git
cargo new hello_cargo --vcs none

# build in debug mode
cargo build

# build and run
cargo run

# test your code
cargo test

# checks your code to catch errors without producing an executable binary
cargo check

# build in release mode(for production)
cargo build --release

# update the dependencies to the latest versions allowed by cargo.toml
cargo update

# build documentation for your project
cargo doc --open

# publish a library to crates.io
cargo publish