🦀 Rust Nuggets

Surprising, delightful, and deep aspects of Rust — one digestible nugget at a time

Every nugget reveals something about Rust's type system, trait system, or ownership model that you might not have noticed at first glance.

Rust code throughout. No other languages.

Nugget 1

The Magic of parse()

How one method call does so much — FromStr, type inference, turbofish, and custom parseable types.

Nugget 2

Making Your Types Printable

Debug and Display — why println! won't work with your struct and how to fix it.

Nugget 3

Copying vs. Moving Values

Why values 'disappear' in Rust — the Copy and Clone traits and ownership basics.

Nugget 4

Comparing Things

Why == doesn't compile on your struct — PartialEq, Eq, and the NaN gotcha.

Nugget 5

Shared Behavior Across Types

Defining a trait, implementing it for Dog and Cat — Rust's version of an interface.

Nugget 6

One Function, Many Types

Trait bounds — fn greet<T: Speak>(a: &T) works with any type that implements Speak.

Nugget 7

Extension Traits

Adding methods to types you don't own — .is_email() on &str and the itertools crate.

Nugget 8

Trait Objects

Storing Dogs and Cats in the same VecBox<dyn Speak> and dynamic dispatch.

Nugget 9

What Is an Iterator?

The Iterator trait, next(), how for loops work, and iter vs into_iter vs iter_mut.

Nugget 10

The Lazy Pipeline

Why map / filter don't do anything until collect() — lazy evaluation vs JavaScript's eager arrays.

Nugget 11

Consuming Your Iterator

sum, count, fold, any, find — the many ways to finish an iteration.

Nugget 12

Iterator Adapters

take, skip, enumerate, zip, chain, step_by — composing with precision.

Nugget 13

Flat and Flatten

When map gives you nested iterators — flat_map and flatten to the rescue.

Nugget 14

IntoIterator

The trait behind every for loop — and making your own types iterable.

Nugget 15

Option and Result as Iterators

map / and_then on Option and Result, and collecting Results in one shot.

Nugget 16

The vec! Macro

Why vec! is a macro, not a function — and the three things it can do that Vec::new() can't.

Nugget 17

Vec Capacity

When Vec::new() causes 20 reallocations and with_capacity() causes one — Vec's growth strategy.


17 nuggets — from traits to iterators, a beginner-friendly tour through Rust's core abstractions