coderef

Rust Quick Reference

Rust essentials: variables, ownership and borrowing, strings, vectors, structs, enums, matching, traits, errors and Cargo.

6 sections · 34 snippets · updated Oct 14, 2026

Click any snippet to copy it.

Basics

Programs and variables.

  • Hello world
  • Variables
  • Types
  • Print / format
  • Convert

Ownership & borrowing

Rust's memory model.

  • Move
  • Clone
  • Borrow (read)
  • Borrow (write)
  • Lifetimes

Strings & collections

Text, vectors and maps.

  • String / &str
  • Append
  • Vector
  • Iterate
  • Map / filter / collect
  • Sum
  • Reverse
  • HashMap
  • Count with entry

Structs, enums & matching

Data types.

  • Struct
  • Methods
  • Enum with data
  • Match
  • If let
  • Trait

Errors

Option and Result.

  • Option
  • Result
  • Propagate with ?
  • Handle
  • Panic

Cargo

Build tool and packages.

  • New project
  • Run / build / test
  • Add a crate
  • Check / lint / format

← All quick references