Rust 1.99 Standard Library Tutorial Curriculum
Toolchain: Rust 1.99 (MSRV; compiler 1.99.0), edition 2024. Format: Each tutorial is designed as a lecture of 15 minutes (hard cap: 30 minutes). If a subject cannot fit under the cap, split it into multiple tutorials and renumber — there is no limit on tutorial count, only on per-tutorial duration. Tutorials are grouped by domain — a thematic area that crosses module boundaries, connecting related types, traits, functions, and macros by use case rather than by where they live in the
stdhierarchy.
Prologue — The Prelude and Implicit Imports
P.1 · What does the Prelude Import and Why?
What's covered?
- Edition-dependent preludes:
v1(2015/2018),rust_2021,rust_2024. - What changed in 2021 (added
TryFrom,TryInto,FromIterator). - What changed in 2024 (added
Future,IntoFuture). - The prelude traits that
forloops, the?operator,collect, and.awaituse, and the names that need no explicit import. - Why understanding the prelude prevents "where does this trait come from?" confusion.
Learn this before Domain 1 if you have ever wondered why certain traits seem to appear from nowhere.
Library Components:
std::prelude::v1std::prelude::rust_2021std::prelude::rust_2024
Domain 1 — Ownership Mechanics in the Standard Library
1.1 · Clone, Copy, and Drop: The Lifecycle Trio
What's covered?
- How
Clone,Copy, andDropinteract. - When the compiler inserts implicit copies vs. when you must clone explicitly.
- The relationship between
CopyandDrop(mutual exclusion). - Shallow vs. deep cloning with
clone_from. - Performance implications of
Cloneon collection types.
Library Components:
std::clone::Clonestd::marker::Copystd::ops::Dropclone_from
1.2 · Borrow, ToOwned, and Cow: Flexible Ownership Boundaries
What's covered?
- The
BorrowandBorrowMuttraits as abstraction over ownership. ToOwnedfor going from borrowed to owned.Cow<'a, B>(clone-on-write) as the bridge that defers allocation.- Real use case: building APIs that accept both
&strandStringwithout forcing the caller to allocate.
Library Components:
std::borrow::Borrowstd::borrow::BorrowMutstd::borrow::ToOwnedstd::borrow::Cow
1.3 · AsRef, AsMut, Into, From: The Conversion Matrix
What's covered?
- When to use
AsRef<T>vs.Borrow<T>. - The blanket implementations that make
From/Intowork. TryFrom/TryIntofor fallible conversions — including numeric range checks,impl TryFrom<char> for usize(stabilized in 1.94), andimpl TryFrom<{integer}> for bool(stabilized in 1.95).ascasting behavior (truncation, sign extension) and whentry_into()is safer.Infallibleas the error type for conversions that cannot fail and its relationship to the never type!.convert::identityas a typed no-op useful in higher-order functions.- Designing public APIs with conversion traits to maximize ergonomics.
Library Components:
std::convert::AsRefstd::convert::AsMutstd::convert::Fromstd::convert::Intostd::convert::TryFromstd::convert::TryIntostd::convert::Infalliblestd::convert::identity
Domain 2 — Error Handling Ecosystem
2.1 · Result and Option: Beyond the Basics
What's covered?
- The full combinator API on
ResultandOption—and_then,or_else,map_or,unwrap_or_default,transpose,flatten,inspect,zip,unzip. - Chaining results with
?. - The
FromResidualtrait behind?. - When
Optionis more appropriate thanResultand vice versa. bool::ok_or/ok_or_else(stabilized in 1.98) for turning a predicate intoResult<(), E>.
Library Components:
std::option::Optionstd::result::Result
2.2 · The Error Trait and Error Propagation Patterns
What's covered?
- Implementing
std::error::Error. - The
source()chain for error causes. Displayvs.Debugfor error formatting.- Downcasting errors with
downcast_ref. - Building custom error hierarchies without third-party crates.
- The deprecated
description()method and why it was superseded. Error::providefor supplying typed context including backtraces (see 2.4 for backtrace capture mechanics).
Library Components:
std::error::Errorstd::fmt::Displaystd::fmt::Debug<dyn Error>::downcast_ref/downcast_mut/Box<dyn Error>::downcast(inherent methods; the sameTypeIdtechnique asstd::any::Any)
2.3 · Panic Infrastructure: Hooks, Unwind, and Abort
What's covered?
panic!,catch_unwind,resume_unwind,set_hook,take_hook.PanicHookInfo(added in 1.81; the old namePanicInfois deprecated since 1.82).- The difference between
std::panic::PanicHookInfoandcore::panic::PanicInfo. UnwindSafeandRefUnwindSafemarker traits;AssertUnwindSafeand itsFrom<T>constructor (stabilized in 1.96).- When
catch_unwindis appropriate (FFI boundaries, thread pools).
Library Components:
std::panicstd::panic::catch_unwindstd::panic::set_hookstd::panic::PanicHookInfostd::panic::UnwindSafestd::panic::RefUnwindSafestd::panic::AssertUnwindSafe
2.4 · Backtraces: Capturing Stack Traces
What's covered?
Backtrace::captureandBacktrace::force_capture.- The
RUST_BACKTRACEenvironment variable. BacktraceStatus—Unsupported,Disabled,Captured.- Embedding backtraces in custom error types via
Error::provide. - When backtraces help (production debugging) and when they hurt (performance).
- How this integrates with the
source()chain from 2.2.
Library Components:
std::backtrace::Backtracestd::backtrace::BacktraceStatus
Domain 3 — Strings and Text Processing
3.1 · String, &str, and the UTF-8 Contract
What's covered?
- Internal representation of
Stringand&str. - Why indexing by
usizedoesn't work. char_indices,chars,bytes.- String slicing and the panic on non-boundary indices.
str::substr_range(1.98) to recover a substring's byte range by pointer arithmetic.String::from_utf8vs.from_utf8_unchecked.as_bytes,into_bytes,from_utf8_lossy.String::from_utf8_lossy_ownedandFromUtf8Error::into_utf8_lossy(1.99) for lossy conversion of an ownedVec<u8>without a copy of valid input.String::from_utf16le/from_utf16beand their lossy siblings (1.98) for decoding endian-tagged UTF-16 byte streams.
Library Components:
std::string::String- primitive
str std::str::from_utf8std::str::Utf8ErrorFromUtf8Error
3.2 · Formatting Mastery: fmt, write!, format_args!
What's covered?
- The
fmtmodule architecture —Display,Debug,Binary,Octal,LowerHex,UpperHex,LowerExp,UpperExp,Pointer. - The
Formatterstruct and its options (padding, alignment, precision, sign, fill). format_args!as a zero-allocation formatting primitive.{integer}::format_intowithNumBuffer(1.98; re-exported fromstd::fmtsince 1.99) for allocation-free decimal integer formatting.- Writing custom
DisplayandDebugimplementations. DebugStruct,DebugTuple,DebugList,DebugMap,DebugSetbuilder helpers.
fmt::Write(for formatting to strings/buffers) andio::Write(for byte streams) are distinct traits —write!andwriteln!work with both via separate blanket implementations; see 8.1 for theio::Writeside.
Library Components:
std::fmtstd::fmt::NumBuffer- all formatting traits
std::fmt::Formatterstd::fmt::Argumentswrite!writeln!format!format_args!
3.3 · Pattern Matching on Strings and FromStr Parsing
What's covered?
- The
Patterntrait and what can be used as a string pattern (char,&str,&[char], closures). - Methods that use patterns:
contains,starts_with,find,rfind,split,splitn,trim_matches,strip_prefix,strip_suffix,strip_circumfix(1.98 — prefix and suffix in one call). FromStrfor parsing arbitrary types from strings.str::parse::<T>()ergonomics.
Library Components:
std::str::pattern::Patternstd::str::FromStrstrmethods
3.4 · OsString, CStr, CString: Non-UTF-8 String Types
What's covered?
- Why
OsStr/OsStringexist (platform-dependent encoding). - Converting between
OsStr,Path,str. CStrandCStringfor C interop — null termination guarantees,as_ptr,from_ptr.- Comparison traits between
CStr,CString, andCow<CStr>(stabilized recently). - When to use each string type.
Library Components:
std::ffi::OsStrstd::ffi::OsStringstd::ffi::CStrstd::ffi::CStringstd::ffi::NulErrorstd::ffi::FromBytesWithNulError
3.5 · ASCII Operations and Character Classification
What's covered?
- The
std::asciimodule. charmethods for classification (is_alphabetic,is_numeric,is_ascii_*,is_uppercase, etc.).- Case conversion with
to_lowercase,to_uppercase(iterator-based because of Unicode). make_ascii_lowercase,make_ascii_uppercaseon[u8]andstr.EscapeDefault,EscapeDebug,EscapeUnicodeiterators.
Library Components:
std::asciistd::char- primitive
charmethods char::from_digitchar::to_digit
Domain 4 — Collections Deep Dive
4.1 · Vec<T>: The Workhorse Collection
What's covered?
- Internal layout (pointer, length, capacity).
- Growth strategy.
with_capacity,reserve,shrink_to_fit,shrink_to.retain,dedup,dedup_by,dedup_by_key.drain,splice,split_off.push_mutandinsert_mutfor getting&mut Tto the just-inserted element (stabilized in 1.95).into_boxed_slice.into_partsandfrom_parts(1.99) to decompose aVecinto(NonNull<T>, length, capacity)and rebuild it.Vecas aDeref<Target = [T]>— the slice method inheritance.extend_from_slicevs.extend.
Library Components:
std::vec::Vecstd::vec::IntoIterstd::vec::Drainstd::vec::Splice
4.2 · HashMap and HashSet: Hashing Internals and Custom Hashers
What's covered?
- SwissTable-based implementation (quadratic probing + SIMD lookup).
- The
EntryAPI (or_insert,or_insert_with,and_modify,or_default). RandomStateandBuildHasher.- Providing custom hashers.
- The
Hashtrait and implementing it correctly (the hash/eq contract). HashSetasHashMap<K, ()>— when sets beat maps.- For in-depth coverage of implementing custom
Hasherstate machines andBuildHasher, see 13.2.
Library Components:
std::collections::HashMapstd::collections::HashSetstd::collections::hash_map::Entrystd::hash::Hashstd::hash::Hasherstd::hash::BuildHasherstd::hash::RandomState
4.3 · BTreeMap, BTreeSet, and Ordered Collections
What's covered?
- B-Tree vs. hash-based collections — when ordering matters.
range,split_off,append.- The
Ordcontract for keys. - Performance characteristics (O(log n) vs. O(1) amortized).
BTreeMap::entry.- Iterating in sorted order.
- Use cases: interval queries, leaderboards, ordered deduplication.
Library Components:
std::collections::BTreeMapstd::collections::BTreeSetstd::collections::btree_map::Entry
4.4 · VecDeque, LinkedList, and BinaryHeap
What's covered?
VecDequeas a growable ring buffer —push_front,push_back,make_contiguous,as_slices, plus thepush_front_mut/push_back_mut/insert_mutfamily (stabilized in 1.95).VecDeque::retain_back(1.99) — the front-side counterpart oftruncate: keep only the lastnelements.- Why
LinkedListis almost never what you want (cache locality, allocation overhead). BinaryHeapas a max-heap priority queue —peek,push,pop,into_sorted_vec.- Relaxed
T: Ordbounds in 1.94 for someBinaryHeapmethods.
Library Components:
std::collections::VecDequestd::collections::LinkedListstd::collections::BinaryHeap
4.5 · Slices and Arrays: The Foundation Types
What's covered?
- Slice methods —
sort,sort_by,sort_unstable,binary_search,chunks,windows,array_windows(stabilized in 1.94),split,contains,rotate_left,rotate_right,fill,swap,reverse. element_offset(new in 1.94).array::from_fn,array::each_ref,array::each_mut, and the stable alternative toarray::try_from_fn(still unstable as of 1.99).- Const generic arrays.
- Range syntax (
a..b,a..=b,..) appears throughout slice indexing — see 14.2 for the fullRangeBoundstrait andBoundtype behind it. - For advanced slice algorithms (partition-point, unstable select, group-by), see 25.2.
Library Components:
- primitive
[T](slice) - primitive
[T; N](array) std::slicestd::array
Domain 5 — Iterators and Lazy Computation
5.1 · Iterator Fundamentals: The Trait and Its Adapters
What's covered?
- The
Iteratortrait andnext(). - Core adapters:
map,filter,filter_map,flat_map,flatten,enumerate,zip,chain,take,skip,take_while,skip_while,step_by,cycle,fuse. - Laziness — no work happens until consumption.
- Why iterators are zero-cost abstractions.
Library Components:
std::iter::Iterator- adapter types in
std::iter
5.2 · Consumers, Collectors, and the FromIterator/Extend Traits
What's covered?
- Terminal operations:
collect,fold,reduce,for_each,sum,product,count,any,all,find,position,min,max,min_by,max_by,min_by_key,max_by_key,nth,last,unzip. FromIteratorfor custom collection types.Extendfor appending.collect::<Result<Vec<_>, _>>()pattern.
Library Components:
std::iter::FromIteratorstd::iter::Extendstd::iter::Sumstd::iter::Product
5.3 · Advanced Iterators: Peekable, Chain, Scan, and Inspect
What's covered?
Peekableand itspeek,peek_mut,next_if,next_if_eq,next_if_map(new in 1.94).scanfor stateful transformations.inspectfor debugging pipelines.by_refto borrow an iterator.clonedvs.copied.intersperse,intersperse_with, andIterator::array_chunks(all still unstable as of 1.99 — nightly-gated example).
Library Components:
std::iter::Peekablestd::iter::Scanstd::iter::Inspectstd::iter::Intersperse
5.4 · DoubleEndedIterator, ExactSizeIterator, and FusedIterator
What's covered?
DoubleEndedIteratorandnext_back— iterating from both ends.rev().ExactSizeIteratorandlen()— when the compiler knows the exact remaining count.FusedIterator— guaranteeingNoneforever after the firstNone;StepBy<I>is fused whenIis fused (1.99).- How these traits enable optimizations in
collectandextend. TrustedLen(unstable but worth knowing about).
Library Components:
std::iter::DoubleEndedIteratorstd::iter::ExactSizeIteratorstd::iter::FusedIterator
5.5 · Creating Iterators: once, empty, repeat, successors, from_fn
What's covered?
- Factory functions for iterators:
iter::once,iter::once_with,iter::empty,iter::repeat,iter::repeat_with,iter::repeat_n(whoseRepeatNgainedDefaultin 1.97),iter::successors,iter::from_fn,iter::from_coroutine(unstable). IntoIteratorand whyforloops work.- Implementing
Iteratorfor custom types.
Library Components:
std::iter::oncestd::iter::emptystd::iter::repeatstd::iter::successorsstd::iter::from_fnstd::iter::IntoIterator
5.6 · ControlFlow: Short-Circuiting Iterator Operations
What's covered?
ControlFlow<B, C>as the generalization ofbreakandcontinue.- How
ControlFlowpowers theTrytrait machinery under?. - Using
ControlFlowwithIterator::try_for_eachandIterator::try_foldfor early-exit iterations without forcingResultorOptionsemantics. - Implementing custom iterators that respect
ControlFlow. - How
ControlFlow::BreakandControlFlow::Continuereplace ad-hoc boolean flags. - Relationship to
FromResidual(see 2.1).
Library Components:
std::ops::ControlFlowstd::iter::Iterator::try_for_eachstd::iter::Iterator::try_fold
Domain 6 — Concurrency and Parallelism
6.1 · Threads: Spawning, Joining, and Thread-Local Storage
What's covered?
thread::spawn,JoinHandle,thread::Builder(naming, stack size).thread::current,thread::park,thread::unpark.thread_local!macro andLocalKey<T>(includingLocalKey<Cell<T>>::update, stable since 1.99).- Scoped threads with
thread::scope— borrowing stack data across threads withoutArc. - When
thread::spawnreturns an error.
Library Components:
std::threadstd::thread::spawnstd::thread::Builderstd::thread::JoinHandlestd::thread::scopethread_local!std::thread::LocalKey
6.2 · Mutex, RwLock, and Poison Recovery
What's covered?
Mutex<T>— wrapping data,lock(),try_lock().MutexGuardand RAII.RwLock<T>—read(),write(),try_read(),try_write().- Poison: what it is,
PoisonError::into_inner()for recovery. Condvarfor wait/notify patterns.- When
RwLockbeatsMutexand when it doesn't (writer starvation).
Library Components:
std::sync::Mutexstd::sync::MutexGuardstd::sync::RwLockstd::sync::RwLockReadGuardstd::sync::RwLockWriteGuardstd::sync::Condvarstd::sync::PoisonErrorstd::sync::TryLockError
6.3 · Atomic Types and Their Operations
What's covered?
- The atomic types:
AtomicBool,AtomicI8throughAtomicI64,AtomicU8throughAtomicU64,AtomicPtr,AtomicUsize,AtomicIsize. - Operations:
load,store,swap,fetch_add,fetch_sub,fetch_or,fetch_and,fetch_xor,fetch_update(a legacy spelling, deprecated since 1.99 in favor oftry_update), and the closure-basedupdate/try_update(stabilized in 1.95). from_mut/from_mut_slice/get_mut_slice(1.98) to view exclusive&mutintegers as atomics and back.- Lock-free counters and flags using only
Relaxedand the "when in doubt" defaultSeqCst. - When an atomic beats a
Mutexand when it doesn't. - Memory orderings appear only as a usage rule of thumb here — the full ordering model is Tutorial 6.4.
Library Components:
std::sync::atomic::AtomicBoolstd::sync::atomic::AtomicUsizestd::sync::atomic::AtomicPtrstd::sync::atomic::Ordering
6.4 · Memory Ordering: Relaxed, Acquire/Release, and SeqCst
What's covered?
- What each
Orderingguarantees and when to use it:Relaxed,Acquire,Release,AcqRel,SeqCst. - The happens-before relation illustrated with the message-passing pattern (data + ready-flag).
compare_exchangevs.compare_exchange_weakand the spurious-failure retry loop idiom.fenceandcompiler_fence.- Common bugs: assuming
Relaxedorders unrelated memory, mixing orderings inconsistently between load and store sides.
Library Components:
std::sync::atomic::Orderingstd::sync::atomic::fencestd::sync::atomic::compiler_fence
6.5 · Channels: mpsc and mpmc Message Passing
What's covered?
mpsc::channel(unbounded) andmpsc::sync_channel(bounded).Sender,SyncSender,Receiver.send,try_send,recv,try_recv,recv_timeout.- The
mpmcmodule (multi-producer, multi-consumer — still unstable as of 1.99; demonstrated with a nightly-gated example, with the "clone theReceiver" pattern it will enable). - Choosing between channels and shared state.
- Backpressure with bounded channels.
Library Components:
std::sync::mpscstd::sync::mpmcSenderReceiverSyncSenderRecvErrorSendErrorTryRecvErrorTrySendError
6.6 · Once, OnceLock, LazyLock, LazyCell: One-Time Initialization
What's covered?
- The full picture of lazy and once-initialization types.
OnceCell(single-threaded, no closure) vs.LazyCell(single-threaded, with closure).OnceLock(multi-threaded, no closure) vs.LazyLock(multi-threaded, with closure).Onceandcall_oncefor global one-shot init.get,get_mut,force,force_mut(new in 1.94) — checking initialization state without forcing.From<T>for pre-initializedLazyCell/LazyLock(stabilized in 1.96).- When to use
staticwithLazyLockvs. a field withLazyCell. - Poisoning behavior differences between
LazyLockandMutex. - The four-cell decision matrix.
Library Components:
std::sync::Oncestd::sync::OnceLockstd::sync::LazyLockstd::cell::OnceCellstd::cell::LazyCell
6.7 · Barrier and Rendezvous Synchronization
What's covered?
Barrierfor synchronizing a fixed number of threads at a checkpoint — all threads block until the last one arrives.BarrierWaitResultandis_leader()for designating one thread to do post-rendezvous work.- Constructing phased algorithms (map-reduce, parallel simulation steps) with repeated barrier usage.
- Comparison with
Condvar(6.2) and channels (6.5) for synchronization: whenBarrieris the right tool.
Library Components:
std::sync::Barrierstd::sync::BarrierWaitResult
6.8 · Send, Sync, and the Marker Trait Contracts
What's covered?
- Why
SendandSyncare auto traits. - What breaks
Send(e.g.,Rc<T>). - What breaks
Sync(e.g.,Cell<T>,RefCell<T>). PhantomDatato manually opt out.- Unsafe implementations of
Send/Syncand when they're justified. - How
Arc<Mutex<T>>satisfies both. - The role of
Unpinin this landscape.
Library Components:
std::marker::Sendstd::marker::Syncstd::marker::Unpinstd::marker::PhantomDatastd::marker::PhantomPinned
Domain 7 — Smart Pointers and Heap Allocation
7.1 · Box<T>: The Simplest Heap Allocation
What's covered?
Box::new,Box::into_raw,Box::from_raw,Box::leak.Box::into_non_null/Box::from_non_null(1.99): the same ownership round trip with aNonNull<T>pointer.- Boxing trait objects (
Box<dyn Trait>). - Boxing recursive types.
Box::into_inner(still unstable as of 1.99 — nightly-gated example; the stable equivalent is the deref-move*boxed).- The
DerefandDerefMutimplementations. - Stack vs. heap placement semantics.
Library Components:
std::boxed::Box
7.2 · Rc<T> and Arc<T>: Reference Counting Strategies
What's covered?
Rc<T>for single-threaded reference counting.Arc<T>for thread-safe reference counting.strong_count,weak_count,Rc::try_unwrap,Arc::try_unwrap.make_mut(clone-on-write).Weak<T>references to break cycles.Rc::new_cyclicfor self-referential data.- Why
Rcis notSend.
Library Components:
std::rc::Rcstd::rc::Weakstd::sync::Arcstd::sync::Weak
7.3 · Cell<T> and RefCell<T>: Interior Mutability
What's covered?
Cell<T>—get,set,replace,take.- Why
CellrequiresCopyforget. RefCell<T>—borrow,borrow_mut,try_borrow,try_borrow_mut.- Runtime borrow checking.
BorrowErrorandBorrowMutError.OnceCellandLazyCellfor single-assignment cells (covered in full at 6.6).- Array-of-cells conversions:
Cell<[T; N]>as[Cell<T>; N]viaAsRef(stabilized in 1.95) alongsideas_slice_of_cells. - The
UnsafeCell<T>primitive underneath.
Library Components:
std::cell::Cellstd::cell::RefCellstd::cell::Refstd::cell::RefMutstd::cell::UnsafeCell
Domain 8 — I/O System
8.1 · Read, Write, BufRead: The I/O Trait Hierarchy
What's covered?
- The three core traits:
Read(bytes in),Write(bytes out),BufRead(buffered reading withread_line,lines,split). BufReaderandBufWriterwrappers.read_to_string,read_to_end,read_exact.write_allvs.write.flush.- Chaining readers with
chain. taketo limit reads.io::copyfor streaming data between aReadand aWritewithout intermediate allocation (it specializes internally for buffered sources and sinks; as of 1.99, std has no publicio::copy_buf).- Note:
io::Write(byte streams) is distinct fromfmt::Write(string/buffer formatting) — both work withwrite!andwriteln!macros via separate trait implementations; see 3.2 for thefmt::Writeside.
Library Components:
std::io::Readstd::io::Writestd::io::BufReadstd::io::BufReaderstd::io::BufWriterstd::io::LineWriterstd::io::copy
8.2 · Cursor, Sink, Empty, Repeat: In-Memory I/O and Binary Parsing
What's covered?
Cursor<T>for treatingVec<u8>or&[u8]as a reader/writer with seek support.io::empty()as/dev/nullfor reads.io::sink()as/dev/nullfor writes.io::repeat(byte)for infinite byte streams.- Binary format parsing: using
Cursor<&[u8]>to sequentially parse a binary format — combiningReadwithSeekto navigate offset tables, readingu32s andf64s in specific byte orders (see 18.1 for endian conversion helpers), writing binary data back withCursor<Vec<u8>>. - Use case: testing I/O code without files and parsing binary file headers (e.g., BMP, PNG).
Library Components:
std::io::Cursorstd::io::Emptystd::io::Sinkstd::io::Repeatstd::io::emptystd::io::sinkstd::io::repeat
8.3 · Seek and Byte-Level Navigation
What's covered?
- The
Seektrait andSeekFromenum (Start,End,Current). stream_positionas a convenience.- Using
SeekwithBufReader(the gotcha of stale buffers). seek_relativeonBufReader.- Use case: parsing binary file formats with offset tables.
Library Components:
std::io::Seekstd::io::SeekFrom
8.4 · std::io::Error: Anatomy of I/O Errors
What's covered?
io::Errorconstruction:Error::new,Error::other,Error::from_raw_os_error.ErrorKindenum — all variants and when each occurs.error.kind()matching.- Custom error payloads.
- Converting other error types into
io::Error. - The
io::Result<T>alias.
Library Components:
std::io::Errorstd::io::ErrorKindstd::io::Result
8.5 · stdin, stdout, stderr: Standard Streams
What's covered?
io::stdin(),io::stdout(),io::stderr()— their locking model (lock()for performance).print!,println!,eprint!,eprintln!.StdinLock,StdoutLock.- Why
println!panics on broken pipes and how to handle it. - Buffering behavior differences between stdout and stderr.
Library Components:
std::io::stdinstd::io::stdoutstd::io::stderrstd::io::Stdinstd::io::Stdoutstd::io::Stderrprint!println!eprint!eprintln!
Domain 9 — Filesystem Operations
9.1 · Reading, Writing, and Creating Files
What's covered?
File::open,File::create,File::create_new.OpenOptionsbuilder —read,write,append,truncate,create,create_new.- Reading a file to string with
fs::read_to_string. - Writing with
fs::write. FileasRead + Write + Seek.- Setting permissions on open.
Library Components:
std::fs::Filestd::fs::OpenOptionsstd::fs::read_to_stringstd::fs::readstd::fs::write
9.2 · Directory Operations and Metadata
What's covered?
fs::create_dir,fs::create_dir_all,fs::remove_dir,fs::remove_dir_all.fs::read_dirand theDirEntryiterator.fs::metadata,fs::symlink_metadata.- The
Metadatastruct —is_file,is_dir,is_symlink,len,modified,created,accessed,permissions. fs::set_permissions.fs::set_timesandfs::set_times_nofollow(1.99) with theFileTimesbuilder, to set timestamps by path.
Library Components:
std::fsstd::fs::DirEntrystd::fs::Metadatastd::fs::Permissionsstd::fs::FileTypestd::fs::FileTimes
9.3 · Path and PathBuf: Cross-Platform Path Manipulation
What's covered?
Pathvs.PathBuf(borrowed vs. owned).join,push,pop,set_extension,set_file_name.- Components:
parent,file_name,file_stem,extension,components,ancestors. canonicalizefor resolving symlinks.- Platform differences (separators, roots, prefixes).
Path::displayfor lossy printing.
Library Components:
std::path::Pathstd::path::PathBufstd::path::Componentstd::path::Prefixstd::path::MAIN_SEPARATOR
9.4 · Symbolic Links, Hard Links, and File Copying
What's covered?
fs::copy,fs::rename,fs::hard_link.- Platform-specific symlink functions in
std::os::unix::fs::symlinkandstd::os::windows::fs::symlink_file/symlink_dir. fs::read_link.- Handling cross-device moves (rename fails, must copy + delete).
- Atomicity guarantees (or lack thereof).
Library Components:
std::fs::copystd::fs::renamestd::fs::hard_linkstd::fs::read_linkstd::os::unix::fsstd::os::windows::fs
Domain 10 — Networking
10.1 · TCP: TcpListener and TcpStream
What's covered?
TcpListener::bind,incoming(),accept().TcpStream::connect,connect_timeout.- Reading and writing on streams.
set_nonblocking,set_read_timeout,set_write_timeout,set_nodelay.shutdownwithShutdown::Read/Write/Both.peek.try_clonefor sharing a socket.
Library Components:
std::net::TcpListenerstd::net::TcpStreamstd::net::Shutdown
10.2 · UDP: Connectionless Communication
What's covered?
UdpSocket::bind,send_to,recv_from.connect+send/recvfor connected UDP.set_broadcast,set_multicast_loop_v4,join_multicast_v4,leave_multicast_v4.set_nonblocking.- Use case: building a simple DNS resolver or game server.
Library Components:
std::net::UdpSocket
10.3 · IP Addresses and Socket Addresses
What's covered?
IpAddr,Ipv4Addr,Ipv6Addr— parsing, constructing, classification (is_loopback,is_multicast,is_private,is_global).SocketAddr,SocketAddrV4,SocketAddrV6.ToSocketAddrstrait for resolution (including DNS).- Why
ToSocketAddrsblocks and how to handle that.
Library Components:
std::net::IpAddrstd::net::Ipv4Addrstd::net::Ipv6Addrstd::net::SocketAddrstd::net::SocketAddrV4std::net::SocketAddrV6std::net::ToSocketAddrsstd::net::AddrParseError
Domain 11 — Time and Duration
11.1 · Instant, SystemTime, and Duration
What's covered?
Instant::now()for monotonic timing (benchmarks, timeouts).SystemTime::now()for wall-clock time.UNIX_EPOCH.Duration—from_secs,from_millis,from_nanos,as_secs_f64,as_secs_f32.- Arithmetic on
InstantandSystemTime(addition, subtraction,elapsed). checked_add,checked_sub,saturating_*.SystemTimeErrorand itsduration()method for negative differences.
Library Components:
std::time::Instantstd::time::SystemTimestd::time::Durationstd::time::UNIX_EPOCHstd::time::SystemTimeError
11.2 · Thread Sleep, Timeouts, and Timed Operations
What's covered?
thread::sleep(andthread::sleep_until, still unstable as of 1.99 — mention only).- Using
DurationwithMutex::try_lock,Condvar::wait_timeout,mpsc::Receiver::recv_timeout,TcpStream::set_read_timeout. - Building a simple rate limiter with
Instant. - Spin-wait vs. sleep tradeoffs.
hint::spin_loopfor busy waiting.
Library Components:
std::thread::sleepstd::time::Durationstd::hint::spin_loop
Domain 12 — Process and Environment Interaction
12.1 · Environment Variables, Args, and Current Directory
What's covered?
env::var,env::var_os,env::vars,env::vars_os.env::set_var(unsafe since 1.84),env::remove_var.env::args,env::args_os.env::current_dir,env::set_current_dir.env::current_exe.env::temp_dir,env::home_dir(un-deprecated in 1.87 after its Windows behavior was fixed).- The safety concerns around
set_varin multithreaded contexts.
Library Components:
std::envstd::env::Argsstd::env::ArgsOsstd::env::Varsstd::env::VarsOsstd::env::VarError
12.2 · Spawning and Managing Child Processes
What's covered?
Command::new,arg,args,env,current_dir,stdin,stdout,stderr.Stdio::piped,Stdio::null,Stdio::inherit.spawnvs.outputvs.status.Child—wait,wait_with_output,kill,try_wait.- Piping between processes.
ExitStatusandExitCode.Termination— the trait that allowsfn main() -> Result<(), E>and custom process exit codes; howExitCode::fromandTermination::reportwork together.
Library Components:
std::process::Commandstd::process::Childstd::process::Outputstd::process::Stdiostd::process::ExitStatusstd::process::ExitCodestd::process::Terminationstd::process::exitstd::process::abort
Domain 13 — Comparing, Ordering, and Hashing
13.1 · PartialEq, Eq, PartialOrd, Ord: The Comparison Hierarchy
What's covered?
- Why four traits? The partial equivalence relation (NaN ≠ NaN).
- Deriving vs. manual implementation.
Ord::cmp,PartialOrd::partial_cmp.Reversefor descending sorts.cmp::min/cmp::maxas standalone functions andOrd::clamp(plus the float inherentclamp).- Implementing comparisons across different types (
PartialEq<Rhs>). - Consistency contract: Eq requires reflexivity; Ord requires totality.
Library Components:
std::cmp::PartialEqstd::cmp::Eqstd::cmp::PartialOrdstd::cmp::Ordstd::cmp::Orderingstd::cmp::Reversestd::cmp::minstd::cmp::maxstd::cmp::min_bystd::cmp::max_bystd::cmp::min_by_keystd::cmp::max_by_key
13.2 · Custom Hashing: Implementing Hash and Building Hashers
What's covered?
- The
Hashtrait and itshashmethod. Hashertrait for state machines.BuildHasherfor constructing hashers.DefaultHasher(SipHash 1-3).- The hash/eq contract (equal values must have equal hashes).
- Writing a custom
Hasher. hash_map::RandomStatefor DOS resistance.- When and why you'd want a non-random hasher (deterministic tests, performance).
- The
Hash/Hasher/BuildHashertrio is introduced in context ofHashMapat 4.2; this tutorial goes deeper on custom implementations.
Library Components:
std::hash::Hashstd::hash::Hasherstd::hash::BuildHasherstd::hash::BuildHasherDefaultstd::hash::RandomStatestd::hash::DefaultHasher
Domain 14 — Operator Overloading
14.1 · Arithmetic and Bitwise Operators
What's covered?
Add,Sub,Mul,Div,Remand their*Assignvariants.Negfor unary minus.- Bitwise:
BitAnd,BitOr,BitXor,Not,Shl,Shrand*Assign. - Implementing operators for custom numeric types.
- Operator overloading with different RHS types.
Library Components:
std::ops::Addthroughstd::ops::ShrAssignstd::ops::Negstd::ops::Not
14.2 · Index, Deref, and the Range Operator Family
What's covered?
IndexandIndexMutfor[]syntax.DerefandDerefMut— deref coercion rules and the "smart pointer" pattern.Range,RangeInclusive,RangeFrom,RangeTo,RangeToInclusive,RangeFull— construction, iteration, and use in slice indexing.- The
RangeBounds<T>trait —start_bound,end_bound,contains— and how to write functions that accept any range expression. Bound::Included,Bound::Excluded,Bound::Unbounded.- Using ranges for slicing, iteration, and pattern matching.
- Exclusive range patterns in
match(stabilized 1.80). - The
..and..=operators as syntactic sugar for these types. - The new
core::rangegeneration (stabilized in 1.96, RFC 3550):range::Range,range::RangeFrom,range::RangeInclusive,range::RangeToInclusiveareCopyand implementIntoIteratorinstead ofIterator— why that matters, converting between legacy and new range types, and the future-edition migration outlook. std::range::legacy(1.98) re-exports the iterator-styleopsrange types under a name that marks them as the generation..sugar still builds.
Library Components:
std::ops::Indexstd::ops::IndexMutstd::ops::Derefstd::ops::DerefMutstd::ops::Rangestd::ops::RangeInclusivestd::ops::RangeFromstd::ops::RangeTostd::ops::RangeToInclusivestd::ops::RangeFullstd::ops::RangeBoundsstd::ops::Boundstd::rangestd::range::legacy
14.3 · Fn, FnMut, FnOnce: Closures as Trait Objects
What's covered?
- The three closure traits and their hierarchy (
FnOnce⊇FnMut⊇Fn). - Why closures implement different traits based on capture behavior.
- Using closures in function signatures (
impl Fn,Box<dyn FnMut>,fnpointer). - The
movekeyword. - Closure size and when they allocate.
- Returning closures from functions.
Library Components:
std::ops::Fnstd::ops::FnMutstd::ops::FnOnce
Domain 15 — Asynchronous Programming Primitives
15.1 · Future, Poll, and the Async Machinery
What's covered?
Futuretrait andpoll.Poll::Readyvs.Poll::Pending.ContextandWaker.- Why
stdprovides the traits but no runtime. - The relationship to
async/awaitsyntax. async fndesugaring.- Building a minimal
block_onexecutor with only the standard library (std::task::Wake+Arc+thread::park/unpark) — no external crates.
Library Components:
std::future::Futurestd::future::poll_fnstd::future::pendingstd::future::readystd::task::Pollstd::task::Contextstd::task::Wakerstd::task::RawWakerstd::task::RawWakerVTablestd::task::Wake
15.2 · Pin: Why Futures Need Pinning
What's covered?
- The self-referential future problem, shown concretely with an
asyncblock that borrows across an.await. - The
Pin<P>contract — what it prevents and what it promises. Unpinas the escape hatch and why almost every type isUnpin.pin!macro for stack pinning;Box::pinfor heap pinning.Pin::new(requiresUnpin).PhantomPinnedto opt out ofUnpin.
Library Components:
std::pin::Pinstd::pin::pin!std::boxed::Box::pinstd::marker::Unpinstd::marker::PhantomPinned
15.3 · Advanced Pinning: Unsafe Construction and Structural Projection
What's covered?
Pin::new_uncheckedand the invariants the caller must uphold.- Structural vs. non-structural pinning — deciding per field whether pinning propagates.
- Hand-writing safe pin projections (the pattern behind the
pin-projectcrate). Pin::as_mut,Pin::get_mut,Pin::into_inner_unchecked.- Building a correct self-referential type with
PhantomPinned+NonNull.
Library Components:
std::pin::Pinstd::ptr::NonNullstd::marker::PhantomPinned
Domain 16 — Memory Management and Unsafe Primitives
16.1 · std::mem: Swaps, Sizes, and Transmutes
What's covered?
mem::size_of,mem::size_of_val,mem::align_of,mem::align_of_val.mem::size_of_val_raw,mem::align_of_val_raw, andLayout::for_value_raw(1.99): size and alignment from a raw pointer, when a reference is not permitted.mem::swap,mem::replace,mem::take(replaces with default).mem::drop(explicit drop).mem::forget(leaking intentionally).mem::transmute— power and peril.mem::zeroed,mem::uninitialized(deprecated).mem::ManuallyDropfor controlled destruction order (including the 1.98-documented guarantee that movingManuallyDrop<Box<T>>after dropping the box is not UB).mem::discriminantfor comparing enum variants.
Library Components:
std::mem::*
16.2 · MaybeUninit: Safe Patterns for Uninitialized Memory
What's covered?
- Why
MaybeUninit<T>exists (replacingmem::uninitialized). MaybeUninit::uninit,MaybeUninit::new,assume_init,assume_init_ref,assume_init_mut,assume_init_drop.- Initializing arrays element-by-element; the
MaybeUninit<[T; N]>⇄[MaybeUninit<T>; N]conversions (stabilized in 1.95). MaybeUninit::zeroed.- Use case: building a fixed-capacity buffer without default constructors.
Library Components:
std::mem::MaybeUninit
16.3 · Raw Pointers in Practice: NonNull, Copying, and Raw References
What's covered?
ptr::null,ptr::null_mut, andNonNull<T>for non-null guarantees (plus the niche optimization it enables).- Creating raw pointers with
&raw const/&raw mut(stabilized 1.82, supersedingaddr_of!). ptr::readandptr::writefor moving values through raw pointers.ptr::copyvs.ptr::copy_nonoverlapping(memmove vs. memcpy semantics).ptr::drop_in_place.ptr::from_ref,ptr::from_mut.- The patterns most likely to appear in safe wrapper code.
Library Components:
std::ptr::NonNullstd::ptr::nullstd::ptr::readstd::ptr::writestd::ptr::copystd::ptr::copy_nonoverlappingstd::ptr::drop_in_place&rawoperators
16.4 · Pointer Arithmetic, Volatile, and Provenance
What's covered?
- Pointer arithmetic —
offset,add,sub,wrapping_add— and the UB conditions that separate them. read_volatile/write_volatileand what volatile does (and does not) guarantee.- Strict provenance APIs (stabilized 1.84):
addr,with_addr,map_addr; exposed provenance:expose_provenance,with_exposed_provenance. - Why pointer↔integer round-trips are subtler than they look.
ptr::danglingfor well-aligned sentinel pointers.
Library Components:
std::ptr- pointer primitive methods
std::ptr::dangling
16.5 · Global Allocator and Allocation APIs
What's covered?
- The
GlobalAlloctrait:alloc,dealloc,realloc,alloc_zeroed. Layout— size and alignment requirements; composing layouts withLayout::extend(stable since 1.44) and withLayout::repeat,Layout::repeat_packed,Layout::extend_packed, andLayout::dangling_ptr(stabilized in 1.95);Layout::for_value_raw(1.99, shown in 16.1).#[global_allocator]attribute for replacing the default allocator.alloc::alloc,alloc::dealloc,alloc::handle_alloc_error.- Why
Allocator(the parameterized allocator trait) is still unstable but worth tracking.
Library Components:
std::alloc::GlobalAllocstd::alloc::Layoutstd::alloc::allocstd::alloc::deallocstd::alloc::reallocstd::alloc::handle_alloc_errorstd::alloc::System
Domain 17 — Type System Utilities
17.1 · Any and Dynamic Typing
What's covered?
Anytrait andTypeId.- Downcasting with
downcast_ref,downcast_mut,downcast(onBox<dyn Any>). TypeId::of::<T>()for runtime type identification.type_name::<T>()andtype_name_of_valfor human-readable type names in diagnostics and generic error messages.- Limitations of
type_name: output format is not guaranteed to be stable or unique across crates — do not use for serialization. - Use cases: heterogeneous collections, plugin architectures, error downcasting, logging.
- The
'staticrequirement onAny.
Library Components:
std::any::Anystd::any::TypeIdstd::any::type_namestd::any::type_name_of_val
17.2 · Marker Traits: Sized, Copy, Send, Sync, Unpin
What's covered?
Sized— the implicit bound and?Sizedfor unsized types.Copysemantics vs.Clone.SendandSync(covered in depth in 6.8 but touched on here from the type system perspective).Unpinand its relationship toPin.PhantomData<T>for expressing unused type parameters, variance, and lifetime relationships.PhantomPinned.
Library Components:
std::marker::Sizedstd::marker::Copystd::marker::Sendstd::marker::Syncstd::marker::Unpinstd::marker::PhantomDatastd::marker::PhantomPinned
17.3 · The Default Trait and Default Values
What's covered?
- Deriving
Default. - Implementing
Defaultmanually. Option::unwrap_or_default().HashMap::entry(..).or_default().- Using
Defaultwithmem::take. - Interaction with
#[non_exhaustive]. - Use case: builder pattern fallbacks, struct initialization with
..Default::default().
Library Components:
std::default::Default
Domain 18 — Numeric Types and Math
18.1 · Integer Methods: Checked, Wrapping, Saturating, Overflowing
What's covered?
- The four arithmetic strategies on every integer type.
checked_add,wrapping_mul,saturating_sub,overflowing_div.pow,isqrt.leading_zeros,trailing_zeros,count_ones,rotate_left,rotate_right,reverse_bits,swap_bytes.- The bit-query family stabilized in 1.97:
bit_width,highest_one,lowest_one,isolate_highest_one,isolate_lowest_one(also onNonZerointegers). - Endian conversion:
to_be,to_le,from_be_bytes,to_le_bytes,to_ne_bytes,from_le_bytes,from_ne_bytes— the primary tools for binary protocol encoding/decoding and working with[u8]byte buffers. [u8]::escape_asciifor displaying raw byte sequences.NonZerotypes, theirMIN/MAXconstants, const methods, and the niche optimization (Option<NonZeroU32>is the same size asu32).- Associated constants (
i32::MAX) are the only current spelling: the legacy module constants (std::i32::MAX) and themin_value()/max_value()functions are deprecated since 1.99.
Library Components:
- Primitive integer types
std::num::NonZero*std::num::Wrappingstd::num::Saturating
18.2 · Floating-Point: IEEE 754, Special Values, and Math Constants
What's covered?
f32andf64methods:floor,ceil,round,trunc,fract,abs,signum,copysign,sqrt,cbrt,ln,log2,log10,exp,exp2,sin,cos,tan,asin,acos,atan,atan2,hypot,powi,powf,mul_add(const in 1.94).- Algebraic operators
algebraic_{add,sub,mul,div,rem}(1.98) that permit reassociation and similar optimizations. NAN,INFINITY,NEG_INFINITY,EPSILON,MIN,MAX,MIN_POSITIVE.- New constants:
EULER_GAMMA,GOLDEN_RATIO(stabilized in 1.94). is_nan,is_finite,is_infinite,is_subnormal,is_sign_positive,classify,total_cmp.
Library Components:
f32f64std::f32::constsstd::f64::consts
18.3 · Parsing Numbers: FromStr, Radix, and Formatting
What's covered?
str::parse::<i32>()andFromStr.i32::from_str_radixfor non-decimal bases.NonZero*::from_str_radix(1.98) so a successful parse is already nonzero.ParseIntError,ParseFloatError.- Formatting numbers: padding, precision, sign display.
num::IntErrorKind— distinguishing empty, invalid digit, overflow, underflow, zero.- Converting between integer sizes safely with
TryFrom(introduced in Tutorial 1.3); since 1.99 theTryFromIntErrormessage says if the value is too large or too small.
Library Components:
std::str::FromStr- integer and float
from_str_radix std::num::ParseIntErrorstd::num::ParseFloatErrorstd::num::IntErrorKind
Domain 19 — Macros from the Standard Library
19.1 · Essential Macros: assert, dbg, todo, unimplemented, unreachable
What's covered?
assert!,assert_eq!,assert_ne!— custom messages, when they compile away (debug_assert_*).assert_matches!anddebug_assert_matches!for pattern-based assertions (stabilized in 1.96; not in the prelude — must be imported).dbg!— how it prints file/line/expression and returns the value.todo!vs.unimplemented!vs.unreachable!— intent signaling.panic!message formatting.
Library Components:
assert!assert_eq!assert_ne!assert_matches!debug_assert!debug_assert_eq!debug_assert_ne!debug_assert_matches!dbg!todo!unimplemented!unreachable!panic!
19.2 · Compile-Time Macros: cfg, env, include, concat, stringify
What's covered?
cfg!for runtime config checks.cfg_select!(stabilized in 1.95) as a compile-time "match on cfg predicates" that replaces thecfg-ifcrate.env!andoption_env!for compile-time env vars.include_str!andinclude_bytes!for embedding files.concat!for compile-time string concatenation.stringify!for turning tokens into a string.file!,line!,column!,module_path!.compile_error!for custom compile-time errors.cfg!vs.#[cfg(...)]vs.cfg_select!.
Library Components:
cfg!cfg_select!env!option_env!include_str!include_bytes!include!concat!stringify!file!line!column!module_path!compile_error!
19.3 · vec!, format!, write!, and Other Constructor Macros
What's covered?
vec![1, 2, 3]andvec![0; n].format!for string building.write!andwriteln!for writing to anyfmt::Writeorio::Write.matches!for boolean pattern matching.todo!as a typed placeholder.thread_local!.- Using these macros effectively in real code.
Library Components:
vec!format!write!writeln!matches!thread_local!
Domain 20 — FFI (Foreign Function Interface)
20.1 · C Types and Calling Conventions
What's covered?
std::ffiC-compatible types:c_char,c_int,c_long,c_float,c_double,c_void, etc.extern "C"blocks.- Calling conventions:
extern "C",extern "system", andextern "stdcall"(a hard error on targets that don't support it —extern "system"is the portable spelling). - ABI compatibility and
#[repr(C)]. - Passing and returning structs across the FFI boundary.
- C-variadic function definitions (
unsafe extern "C" fn f(n: c_int, args: ...)) andVaList(stabilized in 1.99).
Library Components:
std::ffi::c_charstd::ffi::c_intstd::ffi::c_voidstd::ffi::VaList- etc.
20.2 · String Marshalling: CString/CStr and OsString/OsStr at the Boundary
What's covered?
- Creating
CStringfrom Rust strings. - Handling interior null bytes.
- Passing
CStrto C functions. - Receiving C strings as
*const c_charand wrapping inCStr. OsStr/OsStringfor OS-native strings.- Platform-specific extensions:
OsStrExton Unix (as raw bytes),OsStringExton Windows (wide chars).
Library Components:
std::ffi::CStringstd::ffi::CStrstd::ffi::NulErrorstd::ffi::OsStrstd::ffi::OsStringstd::os::unix::ffi::OsStrExtstd::os::windows::ffi::OsStringExt
Domain 21 — OS-Specific Extensions
21.1 · Unix Extensions: File Descriptors, Permissions, Signals
What's covered?
std::os::unix—fs::PermissionsExt(mode bits),fs::MetadataExt(inode, dev, nlink, uid, gid).io::AsRawFd,FromRawFd,IntoRawFd,OwnedFd,BorrowedFd.- Unix domain sockets via
std::os::unix::net(the abstract-namespaceSocketAddrExtis Linux-only, living instd::os::linux::net). process::CommandExt—uid,gid,pre_exec.- Pipe and signal concepts.
Library Components:
std::os::unix::fsstd::os::unix::iostd::os::unix::netstd::os::unix::process
21.2 · Windows Extensions: Handles, Wide Strings, and Process Creation
What's covered?
std::os::windows—io::AsRawHandle,FromRawHandle,IntoRawHandle,OwnedHandle,BorrowedHandle.OsStrExt::encode_wideandOsStringExt::from_wide.fs::MetadataExt(file attributes, creation time).process::CommandExt—creation_flags,raw_arg.- Differences from Unix when writing cross-platform code.
Library Components:
std::os::windows::fsstd::os::windows::iostd::os::windows::processstd::os::windows::ffi
Domain 22 — Compiler Hints and Low-Level Intrinsics
22.1 · std::hint: Guiding the Optimizer
What's covered?
- The complete
std::hintmodule. hint::unreachable_unchecked— promises to the compiler (and the UB if you're wrong).hint::spin_loop— yield for spin-wait loops (see also 11.2).hint::black_box— preventing dead code elimination in benchmarks.hint::assert_uncheckedfor precondition assertions.hint::cold_path(stabilized in 1.95) for marking unlikely branches.- When and why to use each.
Library Components:
std::hint::unreachable_uncheckedstd::hint::spin_loopstd::hint::black_boxstd::hint::assert_uncheckedstd::hint::cold_path
22.2 · SIMD with std::arch: Platform Intrinsics
What's covered?
- Overview of
std::archfor x86, x86_64, ARM, AArch64, WebAssembly. - Feature detection at runtime:
is_x86_feature_detected!,is_aarch64_feature_detected!. - Using SSE/AVX intrinsics within
unsafeblocks. - AVX-512 FP16 intrinsics (stabilized in 1.94) and AArch64 NEON FP16.
#[target_feature(enable = "...")].- Why this matters: hot loops in signal processing, compression, cryptography.
Library Components:
std::arch::x86_64std::arch::aarch64std::arch::wasm32is_x86_feature_detected!is_aarch64_feature_detected!
Domain 23 — Testing, Debugging, and Pattern Matching
23.1 · Debug Formatting and Diagnostic Output
What's covered?
#[derive(Debug)]and when to implementDebugmanually.- Pretty-printing with
{:#?}. dbg!for quick debugging.- Writing custom
Debugimplementations withDebugStruct,DebugTuple,DebugList,DebugMap. fmt::Pointerfor printing addresses.type_name::<T>()andtype_name_of_valfor runtime type inspection (see 17.1 for deeper coverage).
Library Components:
std::fmt::Debugstd::fmt::DebugStructstd::fmt::DebugTuplestd::fmt::DebugListstd::fmt::DebugMapstd::any::type_namedbg!
23.2 · Assertions, Panics, and Test Harness Integration
What's covered?
assert!,assert_eq!,assert_ne!with custom messages.assert_matches!(1.96) for asserting on enum shapes in tests.debug_assert_*variants that compile away in release.#[should_panic]test attribute.#[test]and#[cfg(test)].- Using
Result<(), E>in test functions. - Capturing panics in tests with
catch_unwind. - Building a custom test framework (overview).
Library Components:
assert!assert_eq!assert_ne!debug_assert!std::panic::catch_unwind#[test]#[should_panic]
23.3 · matches!, if let Chains, and Exhaustive Matching Strategies
What's covered?
- The
matches!macro for boolean pattern tests. - Using
matches!with guards. - Nested pattern matching.
- Exclusive range patterns (
start..end, stabilized in 1.80). - Combining patterns with
|. @bindings in patterns.- The
if letandlet elseconstructs; let chains (1.88) and if-let guards inmatcharms (stabilized in 1.95). - How
Option,Result, and custom enums interact with pattern matching.
Library Components:
matches!std::option::Optionstd::result::Result- language-level pattern syntax
Domain 24 — Dynamic Dispatch and Trait Objects
24.1 · dyn Trait, Vtables, and Object Safety
What's covered?
- What makes a trait "object safe."
- The vtable layout — function pointers + size + alignment.
Box<dyn Trait>,&dyn Trait,Arc<dyn Trait>.dyn Trait + Send + Sync + 'staticbounds.- Downcasting with
Any. - Performance implications of dynamic dispatch vs. monomorphization.
dyn Fn(),dyn FnMut(),dyn FnOnce()as callable trait objects.
Library Components:
std::any::Anydynkeywordstd::boxed::Boxstd::ops::Fn*traits
Domain 25 — The Contiguous Memory Triumvirate
25.1 · Vec, Boxed Slices, and Arrays: Choosing the Right Container
What's covered?
Vec<T>— growable.Box<[T]>— heap-allocated, fixed after conversion.[T; N]— stack-allocated, compile-time size.- Conversions between them:
Vec::into_boxed_slice(),into_vec()on aBox<[T]>,<[T; N]>::as_slice(). - When each is optimal (memory overhead, flexibility, stack limits).
- Using
array::from_fnfor constructing arrays from closures. - Iterating a boxed array:
IntoIteratorforBox<[T; N]>,&Box<[T; N]>, and&mut Box<[T; N]>(1.99).
Library Components:
std::vec::Vecstd::boxed::Box- primitive
[T; N] std::array::from_fnstd::array::try_from_fn(unstable as of 1.99 — nightly-gated example)std::boxed::BoxedArrayIntoIter
25.2 · Slice Algorithms: Advanced Sorting, Searching, and Splitting
What's covered?
- Advanced algorithms not covered in 4.5.
sort_by_key,sort_unstable_by_key.binary_search_by,binary_search_by_key,partition_point(find the split point for a sorted predicate).split_at,split_at_mut,split_first,split_last,split_first_mut,split_last_mut.[T]::subslice_rangeand[T]::strip_circumfix(1.98).chunks_exact,chunks_exact_mut, and theas_chunksfamily (stabilized in 1.88;Iterator::array_chunksremains unstable as of 1.99).chunk_by(stabilized in 1.77 — the rename of the formerly unstablegroup_by) for splitting on adjacent-element predicates.select_nth_unstable,select_nth_unstable_by,select_nth_unstable_by_keyfor partial sorting.
Library Components:
- Primitive
[T]methods std::slice
Domain 26 — Cross-Cutting Patterns
26.1 · The Newtype Pattern with Standard Library Traits
What's covered?
- Wrapping a type to change its behavior (sorting, hashing, display).
- Deriving vs. forwarding standard traits on newtypes.
Deref/DerefMutfor transparent access.From/Intofor conversions.- Use case:
Password(String)that redacts inDebug,Meters(f64)with type-safe arithmetic,SortByName(Person)with customOrd.
Library Components:
std::ops::Derefstd::fmt::Debugstd::fmt::Displaystd::cmp::Ordstd::convert::From
26.2 · Builder Patterns with Default and Option
What's covered?
- Using
Default::default()for struct initialization with..Default::default(). Option<T>fields for optional configuration.- Combining
Defaultwith the builder pattern. takeandreplaceonOptionfor consuming builders.unwrap_or_defaultchains.- Real use case: HTTP request builder, database connection options.
Library Components:
std::default::Defaultstd::option::Optionstd::mem::takestd::mem::replace
26.3 · The Iterator + Collect Pattern as a Data Pipeline
What's covered?
- Composing iterator chains as functional data pipelines.
- Collecting into different types:
Vec<T>,HashMap<K, V>,BTreeMap<K, V>,HashSet<T>,String,Result<Vec<T>, E>,Option<Vec<T>>. Iterator::partitionfor splitting.Iterator::unzipfor destructuring pairs.- Performance: avoiding intermediate allocations with
extendandchain.
Library Components:
std::iter::Iteratorstd::iter::FromIteratorstd::iter::Extend
Appendix A — Stabilizations Highlighted from Rust 1.94–1.99
Note: The curriculum targets Rust 1.99 (MSRV; compiler 1.99.0). This table maps stabilizations from releases 1.94 through 1.99 (all verified against the official release notes) to the tutorials that showcase them.
| API | Stabilized | Domain | Tutorial |
|---|---|---|---|
<[T]>::array_windows | 1.94 | Collections, Slices | 4.5, 25.2 |
<[T]>::element_offset | 1.94 | Collections, Slices | 4.5 |
LazyCell/LazyLock get, get_mut, force_mut | 1.94 | Lazy Evaluation | 6.6 |
Peekable::next_if_map | 1.94 | Iterators | 5.3 |
impl TryFrom<char> for usize | 1.94 | Conversions | 1.3 |
f32/f64 consts::EULER_GAMMA, consts::GOLDEN_RATIO | 1.94 | Numerics | 18.2 |
f32::mul_add / f64::mul_add (const) | 1.94 | Numerics | 18.2 |
| AVX-512 FP16 + AArch64 NEON FP16 intrinsics | 1.94 | SIMD | 22.2 |
Relaxed T: Ord on BinaryHeap methods | 1.94 | Collections | 4.4 |
cfg_select! | 1.95 | Macros | 19.2 |
if-let guards in match arms | 1.95 | Pattern Matching | 23.3 |
Atomic*::update / try_update | 1.95 | Concurrency | 6.3 |
Vec::push_mut, Vec::insert_mut | 1.95 | Collections | 4.1 |
VecDeque/LinkedList push_*_mut, insert_mut | 1.95 | Collections | 4.4 |
impl TryFrom<{integer}> for bool | 1.95 | Conversions | 1.3 |
MaybeUninit<[T; N]> ⇄ [MaybeUninit<T>; N] conversions | 1.95 | Unsafe Memory | 16.2 |
Cell<[T; N]>: AsRef<[Cell<T>]> family | 1.95 | Interior Mutability | 7.3 |
hint::cold_path | 1.95 | Compiler Hints | 22.1 |
Layout::repeat, Layout::repeat_packed, Layout::extend_packed, Layout::dangling_ptr | 1.95 | Allocation | 16.5 |
assert_matches!, debug_assert_matches! | 1.96 | Macros, Testing | 19.1, 23.2 |
core::range::{Range, RangeFrom, RangeInclusive, RangeToInclusive} (RFC 3550) | 1.96 | Operators | 14.2 |
From<T> for LazyCell/LazyLock | 1.96 | Lazy Evaluation | 6.6 |
From<T> for AssertUnwindSafe<T> | 1.96 | Panics | 2.3 |
Integer bit_width, highest_one, lowest_one, isolate_highest_one, isolate_lowest_one (incl. NonZero) | 1.97 | Numerics | 18.1 |
Default for iter::RepeatN | 1.97 | Iterators | 5.5 |
char::is_control (const) | 1.97 | Text | 3.5 |
str::substr_range, [T]::subslice_range | 1.98 | Text, Slices | 3.1, 25.2 |
str::strip_circumfix, [T]::strip_circumfix | 1.98 | Text, Slices | 3.3, 25.2 |
core::fmt::NumBuffer, {integer}::format_into | 1.98 | Formatting | 3.2 |
{f32,f64}::algebraic_{add,sub,mul,div,rem} | 1.98 | Numerics | 18.2 |
NonZero<{integer}>::from_str_radix | 1.98 | Numerics | 18.3 |
String::from_utf16le / from_utf16be (and lossy) | 1.98 | Text | 3.1 |
Atomic*::from_mut, from_mut_slice, get_mut_slice | 1.98 | Concurrency | 6.3 |
std::range::legacy | 1.98 | Operators | 14.2 |
bool::ok_or, bool::ok_or_else | 1.98 | Error Handling | 2.1 |
ManuallyDrop<Box<T>> move-after-drop documented as not UB | 1.98 | Memory | 16.1 |
String::from_utf8_lossy_owned, FromUtf8Error::into_utf8_lossy | 1.99 | Text | 3.1 |
NumBuffer re-exported from std::fmt (and alloc::fmt) | 1.99 | Formatting | 3.2 |
Vec::into_parts, Vec::from_parts | 1.99 | Collections | 4.1 |
VecDeque::retain_back | 1.99 | Collections | 4.4 |
FusedIterator for StepBy<I> | 1.99 | Iterators | 5.4 |
LocalKey<Cell<T>>::update | 1.99 | Concurrency, Macros | 6.1, 19.3 |
Atomic*::fetch_update deprecated (renamed to try_update) | 1.99 | Concurrency | 6.3 |
Box::into_non_null, Box::from_non_null | 1.99 | Smart Pointers | 7.1 |
fs::set_times, fs::set_times_nofollow | 1.99 | Filesystem | 9.2 |
mem::size_of_val_raw, mem::align_of_val_raw, Layout::for_value_raw | 1.99 | Memory, Allocation | 16.1, 16.5 |
TryFromIntError messages distinguish "too large" and "too small" | 1.99 | Conversions, Numerics | 1.3, 18.3 |
Legacy integer and float module constants (std::i32::MAX, std::f64::EPSILON) deprecated | 1.99 | Numerics | 18.1 |
C-variadic function definitions, core::ffi::VaList | 1.99 | FFI | 20.1 |
IntoIterator for Box<[T; N]>, &Box<[T; N]>, &mut Box<[T; N]> | 1.99 | Contiguous Memory | 25.1 |
Appendix B — Tutorial Index by Library Module
| Module | Tutorials |
|---|---|
std::alloc | 16.5 |
std::any | 17.1, 23.1 |
std::arch | 22.2 |
std::array | 4.5, 25.1 |
std::ascii | 3.5 |
std::backtrace | 2.4 |
std::borrow | 1.2 |
std::boxed | 7.1, 25.1 |
std::cell | 6.6, 7.3 |
std::char | 3.5 |
std::clone | 1.1 |
std::cmp | 13.1 |
std::collections | 4.1–4.4 |
std::convert | 1.3 |
std::default | 17.3, 26.2 |
std::env | 12.1 |
std::error | 2.2 |
std::ffi | 3.4, 20.1, 20.2 |
std::fmt | 3.2, 23.1 |
std::fs | 9.1–9.4 |
std::future | 15.1 |
std::hash | 4.2, 13.2 |
std::hint | 11.2, 22.1 |
std::io | 8.1–8.5 |
std::iter | 5.1–5.6, 26.3 |
std::marker | 6.8, 17.2 |
std::mem | 16.1, 16.2, 26.2 |
std::net | 10.1–10.3 |
std::num | 18.1, 18.3 |
std::ops | 5.6, 14.1–14.3 |
std::option | 2.1, 23.3 |
std::os | 21.1, 21.2 |
std::panic | 2.3, 23.2 |
std::path | 9.3 |
std::pin | 15.2, 15.3 |
std::prelude | P.1 |
std::process | 12.2 |
std::ptr | 16.3, 16.4 |
std::rc | 7.2 |
std::result | 2.1, 23.3 |
std::slice | 4.5, 25.2 |
std::str | 3.1, 3.3 |
std::string | 3.1 |
std::range | 14.2 |
std::sync | 6.1–6.8 |
std::task | 15.1 |
std::thread | 6.1, 11.2 |
std::time | 11.1, 11.2 |
std::vec | 4.1, 25.1 |
Total: 26 domains + prologue, 88 tutorials (~22 hours of video content at an average of 15 min each)