Rust by Example
The official collection of short, runnable Rust examples, from primitives and structs to traits, generics, error handling, closures and Cargo. Ideal to keep open while you write: find the feature you need, read one example, and run it in the page.
8.1k (rust-lang/rust-by-example)
GitHub · Sept 2026
Guide
Other
The Rust Project
Look-ups as you go, or about a week straight through
Beginner
Free
What it is
Rust by Example (RBE) is a collection of runnable examples that illustrate Rust concepts and the standard library. It is published by the Rust project on doc.rust-lang.org next to the Rust book, and it is included with the documentation that rustup installs. Most examples can be edited and run right in the page.
How it differs from the Rust book
The book teaches in long chapters with explanations first. Rust by Example is the opposite: very short pages that show a feature in code with a few lines of commentary. That makes it a poor first introduction to ownership, but an excellent reference when you remember a feature exists and want to see exactly how it is written.
What it covers
More than twenty chapters: primitives, custom types (structs and enums), variable bindings, types and conversion, flow control and match, functions and closures, modules, crates and Cargo, attributes, generics, scoping rules including ownership, borrowing and lifetimes, traits, macros, error handling with Option, Result and ?, standard library types and collections, threads, file I/O, testing, unsafe code and documentation.
How to use it for backend work
Keep it open next to your editor. When a handler needs a custom error type, read the error handling pages. When you need a trait with a generic bound, find the traits and generics pages. The error handling chapter in particular shows several ways to combine error types, which is the problem every service meets early.
How long it takes
As a reference, a few minutes per look-up. Reading it straight through takes around a week of evenings, and works best after the first half of the Rust book.
Prerequisites
Basic programming in any language. For the ownership and lifetimes pages, read the matching chapters of the Rust book first.
Free or paid?
Free and open source.
What you can do after it
Look up and apply any core Rust feature quickly, and recognise idiomatic patterns when you read other people's crates.
Common questions
Book or Rust by Example first? The book first for ownership and borrowing, then Rust by Example as your quick reference.
Is there practice? Some pages include small activities; for structured practice use Rustlings or Exercism.
Ready to start?
Opens on The Rust Project in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.