Rust Documentation and the Standard Library
Rust ships with a layered standard library and an integrated offline and online documentation ecosystem (rustdoc, rustup doc, and docs.rs). Understanding how the standard library is split into core, alloc, and std—and how to navigate its API reference—lets you locate types, traits, and methods immediately.
The Three-Tier Standard Library Architecture (core, alloc, std)
Unlike C or C++—where the standard library is a monolithic set of headers tied to the operating system's libc—Rust splits its standard library into three concentric crates so that the exact same foundational types work on bare-metal microcontrollers and full desktop operating systems:
+-----------------------------------------------------------------------+
| std (The Standard Library — default for applications & OS targets) |
| - Filesystem (`std::fs`), Networking (`std::net`), Threads (`thread`)|
| - Environment (`std::env`), Process (`std::process`), Time (`time`) |
| +---------------------------------------------------------------+ |
| | alloc (Heap Allocation Crate — requires a memory allocator) | |
| | - `Box<T>`, `Vec<T>`, `String`, `Rc<T>`, `Arc<T>`, `BTreeMap`| |
| | +-------------------------------------------------------+ | |
| | | core (Dependency-Free Foundation — `#![no_std]` safe) | | |
| | | - Primitives (`i32`, `bool`, `char`, `str`, `[T]`) | | |
| | | - `Option<T>`, `Result<T, E>`, `Iterator`, `Future` | | |
| | | - `Copy`, `Clone`, `Drop`, `Send`, `Sync`, `ops::*` | | |
| | +-------------------------------------------------------+ | |
| +---------------------------------------------------------------+ |
+-----------------------------------------------------------------------+
| Crate | Requires OS? | Requires Heap Allocator? | Key Contents |
|---|---|---|---|
core |
No | No | Option, Result, Iterator, Future, Slice, str, atomic types (core::sync::atomic), SIMD, and operator traits (core::ops) |
alloc |
No | Yes (#[global_allocator]) |
Box<T>, Vec<T>, String, VecDeque<T>, BTreeMap<K, V>, Rc<T>, Arc<T>, Cow<T> |
std |
Yes | Yes | Re-exports everything from core and alloc, plus OS facilities: fs, net, io, thread, sync::Mutex, env, process, time |
In normal programs (where std is linked automatically), items from core and alloc are re-exported directly under std—meaning std::option::Option and core::option::Option (and std::vec::Vec and alloc::vec::Vec) are the exact same types.
Major Modules in std
| Module | What It Provides |
|---|---|
std::option & std::result |
Optional values (Option<T>) and recoverable error handling (Result<T, E>) |
std::iter |
The Iterator trait and adapters (map, filter, fold, zip, chain) |
std::collections |
HashMap, HashSet, BTreeMap, BTreeSet, VecDeque, BinaryHeap, LinkedList |
std::string & std::str |
Owned UTF-8 strings (String) and borrowed UTF-8 string slices (&str) |
std::vec & std::slice |
Growable heap arrays (Vec<T>) and contiguous views (&[T], &mut [T]) |
std::io & std::fs |
Buffered streams (Read, Write, BufReader) and filesystem operations (File) |
std::net |
TCP and UDP sockets (TcpListener, TcpStream, UdpSocket, IpAddr) |
std::thread & std::sync |
OS threads, channels (mpsc), locks (Mutex, RwLock), and shared pointers (Arc) |
std::mem & std::ptr |
Memory inspection (size_of, swap, replace, take) and pointer operations |
std::convert & std::cmp |
Value conversions (From, Into, TryFrom) and ordering (PartialEq, Ord) |
Official Documentation Books ("The Rust Bookshelf")
Every rustup installation includes an offline copy of the official Rust documentation bookshelf, accessible via rustup doc:
| Command | Online URL | Title & Focus |
|---|---|---|
rustup doc --std |
https://doc.rust-lang.org/std/ |
Standard Library API Reference: Searchable reference for every module, struct, trait, and method in std, core, and alloc |
rustup doc --book |
https://doc.rust-lang.org/book/ |
The Rust Programming Language: The official tutorial textbook covering Rust concepts |
rustup doc --reference |
https://doc.rust-lang.org/reference/ |
The Rust Reference: Formal specification of Rust grammar, memory model, and type rules |
rustup doc --rust-by-example |
https://doc.rust-lang.org/rust-by-example/ |
Rust by Example: Collection of runnable code examples organized by topic |
rustup doc --cargo |
https://doc.rust-lang.org/cargo/ |
The Cargo Book: Complete guide to Cargo.toml, workspaces, profiles, and build scripts |
rustup doc --nomicon |
https://doc.rust-lang.org/nomicon/ |
The Rustonomicon: Deep dive into unsafe Rust, raw pointers, variance, and FFI |
rustup doc --error-index |
https://doc.rust-lang.org/error_codes/ |
Rust Compiler Error Index: Explanations for every E0xxx compiler error code |
You can jump straight to any specific standard library type or module from your terminal:
rustup doc std::collections::HashMap
rustup doc std::iter::Iterator
Reading a rustdoc API Page Effectively
Every page generated by rustdoc (both in the standard library and on https://docs.rs for third-party crates) follows a standardized structure:
- Item Declaration Box: Shows the exact signature (
pub struct Vec<T, A: Allocator = Global>), showing generic parameters and bounds. - Inherent Implementations (
impl<T> Vec<T>): Lists methods defined directly on the type itself (such asVec::new,Vec::with_capacity,Vec::push). - Deref Target Methods (
Methods from Deref<Target = [T]>): For smart pointers and growable containers (Vec<T>derefs to[T];Stringderefs tostr),rustdoclists all methods inherited automatically from the target slice type! - Trait Implementations (
Trait Implementations): Lists every trait implemented by the type (Clone,Debug,IntoIterator,From<...>,Index<usize>). - Type-Driven Search (
Sshortcut): Pressingson anyrustdocpage opens the search bar. You can search not only by function name, but also by type signature using->:- Typing
vec -> sliceor&str -> usizefinds functions taking those argument types and returning that output type!
- Typing