An introduction to Rust

ferris

The specs

  • Compiled
  • Strong and Statically typed
  • Imperative
  • No garbage collection
  • Advanced type system

Philosophy

Basic Tooling

  • rustup
  • Cargo

rustup

Rust toolchain installer

Visit rustup.rs for installation instructions

rustup

rustup

rustup

rustup

rustup

rustup

cargo

Rust package manager

cargo

cargo_init

cargo

cargo_run

cargo project structure

cargo.toml

cargo_deps

cargo.lock


# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
 "gimli",
]
  

Immutability by default

Ownership

Scopes

Ownership

vs C++

Borrow Checker Rules

  • You can have either one mutable reference or any number of immutable references.
  • References must always be valid.

Ownership

Ownership

Ownership

Ownership

Type System

First class support for algebraic data types

Product Types

aka structs

Sum Types

aka enums

Structs and enums

Pattern Matching

Pattern Matching

Pattern Matching

Generics

Traits

Traits and Generics

Putting it all together

Transformations and State machines

Error handling

Option<T>

Option<T>

Result<T, E>

Result<T, E>

panic!

But wait, there's more

  • Concurrency
  • Smart Pointers
  • Functional Language Features
  • Async
  • Macros
  • Unsafe Rust
  • Foreign Function Interface

Well known crates

CLI Parsing clap
Serialization serde
Async Programming tokio
SQL Queries sqlx
HTTP Client reqwest
Web framework Rocket
Game Engine Bevy

Tooling

LSP rust-analyzer
Linter clippy
Formatter rustfmt

sites

crates.io Crate registry
docs.rs Automatic documentation
play.rust-lang.org Rust playground

Learning Resources

Where to find me