Skip to content

Cheat sheets

Level: reference · the shelf

One line: One of these is maintained and the rest are frozen — which is harmless for memory layout, since the diagrams have not changed, and disqualifying for an iterator list, which has missed eight years of adapters.

Every link checked 2026-08-30 with a full GET rather than a HEAD, because a bot-blocked 403 answers a HEAD as though it were fine. The one dead entry is named below rather than quietly dropped.

A cheat sheet earns its place by answering "what is this called?" faster than search does. That is a narrow job, and the failure mode is specific: a frozen sheet does not look frozen, so you go on trusting a table that stopped being complete years ago.

The one to keep open

cheats.rs ↗Reference. Maintained, enormous, and the only one on this page that is current. The language, the standard library, and the memory-layout diagrams nothing else has. Two deep links worth bookmarking on their own:

Section Why
Standard library types ↗ every container drawn — the ptr / len / capacity boxes over a heap allocation, with subscripts giving the size on 16-, 32- and 64-bit targets
String conversions ↗ the whole matrix — every source type, every target, the call that gets you there

It also ships as a printable PDF, which is the form most people actually want: A4 ↗ · Letter ↗. The links inside the PDF still work.

Its source is public — ralfbiedert/cheats.rs ↗ — which is worth knowing for two reasons beyond filing a correction. The licence is CC-BY (the legal page ↗ states it, with Rust snippets released CC-0 and a requirement that any reproduction change the Operator section and not appear endorsed by the author), so the diagrams may be reused with credit rather than only linked. And there are no diagrams to download. The whole page carries exactly two <img> tags — a GitHub ribbon and the Ferris logo — because every memory-layout figure on it, the byte boxes and the lifetime strips alike, is drawn in HTML and CSS. Reusing one means re-drawing it, not copying a file, which is why the figures in this library are built as text instead: a box diagram in a fenced block diffs, greps, and reads the same in both themes.

Chapter by chapter, against this library

cheats.rs is a lookup surface for the whole language, so it doubles as a map of what a Rust library ought to cover. Its chapters are on the left; where this library says the same thing at teaching length, the page is on the right. The blanks are real — they are the gaps, named rather than papered over, and they are the honest answer to "does this library cover Rust?".

cheats.rs Here
Data Structures ↗ Structs · Enums · Collections
References & Pointers ↗ Ownership
Functions & Behavior ↗ Traits · Closures
Control Flow ↗ Control flow
Organizing Code ↗ Modules
Type Aliases and Casts ↗ Conversion
Macros & Attributes ↗ Macros
Pattern Matching ↗ Pattern matching
Generics & Constraints ↗ Generics
Higher-Ranked Items ↗
Strings & Chars ↗ Strings
Documentation ↗ Doc tests, which is the half that runs
The Abstract Machine ↗ Compilers
Memory & Lifetimes ↗ Borrowed state · What &'a T claims · At the call site
Basic Types ↗ Numbers and bytes
Custom Types ↗ Structs · Enums · What a union is
Pointer Meta ↗ Static vs dynamic dispatch covers the vtable; the fat-pointer layout itself is not drawn here
Standard Library Types ↗ Collections · Strings · Rc
One-Liners ↗ row by row, below — the one chapter small enough to check exhaustively
Thread Safety ↗ Send and Sync
Atomics & Cache ↗ RwLock and atomics
Iterators ↗ Iterators · Adapters, by job
Number Conversions ↗ Conversion · Numbers and bytes
String Conversions ↗ Making a String
String Output ↗ Strings
Project Anatomy ↗ Scaffolding
Cargo ↗ Tooling
Cross Compilation ↗ Targets and triples
Tooling Directives ↗ Strict lints
Types, Traits, Generics ↗ Traits · Generics
Foreign Types and Traits ↗ Traits, for the orphan rule
Type Conversions ↗ Conversion
Performance Tips ↗
Async-Await 101 ↗ only at the edges: Iterator vs Stream and instrumenting async
Closures in APIs ↗ Function pointers
Unsafe, Unsound, Undefined ↗ What unsafe turns off · C and C++
API Stability ↗

Four blanks, and they are not the same kind of blank. Higher-ranked items (for<'a>) and API stability are missing because nothing here has needed them yet. Performance tips is missing on purpose so far: every claim on such a page wants a measurement, and this library has no benchmark harness, so writing one would mean asserting numbers it cannot check — the one thing the answer-key rule exists to prevent. Async is the largest, and it is a section rather than a page.

The One-Liners, row by row

One-Liners ↗ is the odd chapter out on cheats.rs: five tabs of snippets rather than concepts, admitted under three rules its source states in a comment — std only, "most people" should have hit the problem, and it must not be a trivial method on an obvious struct. That makes it the nearest thing the sheet has to a syllabus for a library like this one, and at twenty-six rows it is small enough to check exhaustively rather than chapter by chapter.

Fourteen rows land on a written lesson, four land on a stub, and eight have nothing. The kata column is not decoration. A row with a page but no ## Practice is one you can read and still not write from memory afterwards — which, for a chapter whose subject is snippets you forget, is the whole failure mode.

Strings — eight of nine, two with a kata

Snippet Here Kata
format!("{x}{y}") Concatenating strings, with the {x} capture itself in The braces take a name. The format mini-language — the {:>8} / {:.3} half — is still a stub
write!(x, "{y}") Building a String; the Write trait under it is a stub
s.split(pattern) str::split, and Inside a Split for why {:?} prints a struct instead of the pieces
… with &str str methods — one Pattern table for all four shapes, each with a compiled page behind it
… with char (same table)
… with closure (same table)
s.split_whitespace() str::split_whitespace
s.lines() str::lines
Regex::new(r"\s")?.split(…)

The regex blank is structural rather than an oversight. run_examples.py builds each example with a bare rustc --edition 2024 — no --extern, no cargo — so an example can use nothing outside std. That is the same rule cheats.rs applies to this chapter, and the reason it flags that one row as needing a crate.

The six blanks in the kata column are the honest finding here. The str and String method pages are 125 reference pages with a compiled program each and no exercise anywhere in the set — deliberate, in that a reference page answers a question you already have, but it does mean the split family is a set of pages you consult rather than a skill you own.

I/O — one of three

Snippet Here Kata
File::create(PATH)? Opening a file — a stub
OpenOptions::new()…open(PATH)? (same stub)
read_to_string(path)? Reading lines efficiently, which prices it against lines() and a reused buffer

Files is six pages, five of them stubs, and no kata in the section.

Macros — none of two

Both rows are macro_rules! with variable arguments ($($args:expr),* and expanding it with $( f($args); )*), and Macros is a stub that explains what the ! means and stops. Nothing in this library writes a macro. That is the largest single gap the chapter exposes; it belongs in Control flow, where eight of nine pages are stubs.

Transforms — all five, and the strongest corner

These rows are not snippets; each points at another sheet for "everything you can turn this type into". The destinations are where this library goes deepest.

Starting type Here
Option<T> -> … Option and Result — 27 pages, 23 of them carrying a kata
Result<T, R> -> … (same section), plus Errors
Iterator<Item=T> -> … Adapters, by job
&[T] -> … Arrays and slices · Vec methods
Future<T> -> … Iterator vs Stream alone — the async blank named above

Esoterics — none of seven

Snippet Where it would go
wants_closure({ let c = outer.clone(); move || use_clone(c) }) Closures · The move keyword
iter.try_for_each(|x| { Ok::<(), Error>(()) })? Errors · Iterators
Cell::from_mut(mut_slice).as_slice_of_cells() Interior mutability
&original_slice[offset..][..length] Arrays and slices
const _: Option<&dyn T> = None; Static vs dynamic dispatch, which covers dyn compatibility but not this canary for it
the semver trick Cargo dependencies
pub(crate) use internal_macro; The use declaration

Seven rows, seven pages that already exist, and a paragraph each would close the tab. It is the cheapest gap on this list, and — by the rule cheats.rs uses to admit a row at all — the one a reader is least likely to find anywhere else.

And the Cookbook it points to

The chapter's own header sends you to the Rust Cookbook ↗ for more, and that link is worth following with the std-only rule in mind, because it is the mirror image of this library. Its recipes are organised by task — compression, cryptography, databases, images, HTTP, parsing with nom — and nearly every one is a crate call. The overlap with what can be built here is the handful of chapters that stay inside std: text processing, some of the file-system and command-line recipes, error handling, and the concurrency primitives. Everything else is a reason the sections that name a crate — Data, Clients, Observability — are stubs here and cannot graduate the usual way: the mechanism gets modelled in std, where the check can see it, and the crate's real API stays a link to the crate's own versioned docs.

Memory layout, on one page

Both of these are frozen and both are still correct, because what they draw has not moved.

Rust container cheat sheet ↗Reference. Box<T>, Vec<T>, Box<[T]>, Box<Trait>, &T, &[T], Rc, Arc, Mutex, Cell, RefCell and an enum, all drawn to the same scale on one sheet, with the conversions between them as arrows. Its own credit line reads "by Raph Levien, Copyright 2017 Google Inc., released under Creative Commons BY, 2017-04-21, version 0.0.3"; the Google Slides original ↗ is still up. One caution that applies to every diagram of this kind: it draws Vec as ptr, cap, len and cheats.rs draws it as ptr, len, capacity, and neither is wrong, because the field order of Vec is explicitly not guaranteed ↗. Read them as what a value is made of, never as a layout you can rely on.

Rust Memory Container Cheat-sheet ↗Reference. The same idea by Usagi Ito, MIT-licensed, and the one to print: SVG plus PNG at 3840×2160 down to 1280×720, in nine variants including dark, light and monochrome. Denser than Levien's and less good at the arrows; better on a wall.

Frozen, and worth knowing why

Rust Iterator Cheat Sheet ↗Dated. Its own header says "Last updated: Rust 1.17.0, Itertools 0.6.0" — that is 2017. The organising idea is still the best one going: it groups adapters by what you want to do, with a one-line summary each, and it covers std and itertools side by side. What it cannot do is tell you about anything added since, and the misses are ordinary methods you will reach for — step_by, try_fold, copied, reduce, map_while and is_sorted are all absent. Use it to find the shape of the method you want, then confirm the name in Iterator. Or read Adapters, by job, which is the same idea kept current and with the output proved.

phaiax/rust-cheatsheet ↗Dated. Method signatures for Vec, HashMap, Option and Result grouped by task — accessing, adding, removing — pulled from the std docs of its day. It states no version; the examples inside are marked 1.4 to 1.7, which places it in 2016. std's own docs now do this job better and are current, so this is here for completeness rather than as a recommendation.

The cheat sheets that ship with the language

Three official pages that are cheat sheets in everything but name, and the only ones that cannot go stale:

Page Answers
std::collections"Which collection should I use?" the choice between Vec, VecDeque, HashMap, BTreeMap, HashSet and the rest, with the cost table underneath it
std::fmt the formatting mini-language — {:>8}, {:.3}, {:#x}, {:#?} — which nobody remembers and everybody re-looks-up
Rust API Guidelines checklist ↗ a page of one-line rules to read down before publishing a crate

Dead

Periodic Table of Rust Types (cosmic.mearie.org, Kang Seonghoon, 2014) — the host does not answer at all, over either scheme, as of the date at the top of this page. It is named here because a shelf that only lists what works cannot be trusted about anything else. It was a good sheet: values, references, raw pointers and smart pointers arranged as a grid by ownership and mutability.

The ones already in this library

Not cheat sheets by name, but the same job with a program behind the numbers:


See also

  • Books — the reading shelf, where cheats.rs also appears under On the desk
  • Official docs — when the question has a normative answer rather than a quick one
  • Resources — the map of all five shelves, organised by the moment you are in

Po polsku

Ściągawka (cheat sheet) ma jedno zadanie: odpowiedzieć na pytanie „jak to się nazywa?” szybciej niż wyszukiwarka. Kłopot, o którym jest ta strona, polega na tym, że zamrożona ściągawka nie wygląda na zamrożoną — tabela sprzed ośmiu lat wygląda dokładnie tak samo jak tabela sprzed tygodnia. Dla rysunku pamięci (Box, Vec, Rc) to nie szkodzi, bo to, co rysuje, się nie ruszyło; dla listy adapterów iteratora to dyskwalifikacja — arkusz Daniela Keepa stanął na Ruscie 1.17 i nie zna ani step_by, ani copied, ani reduce, ani map_while. Stąd nawyk wart wyrobienia: najpierw poszukaj daty albo numeru wersji na górze arkusza, a nazwę metody potwierdź w dokumentacji std, która jako jedyna nie może się zdezaktualizować.

Polskiego czytelnika ta pułapka dotyczy mocniej niż angielskiego, i to nie z powodu języka, tylko objętości: materiałów o Ruscie po polsku jest niewiele i prawie żaden nie jest utrzymywany — Tour of Rust po polsku urywa się na rozdziale 5, a spora część polskich wpisów blogowych opisuje jeszcze stan sprzed edycji 2018. Dlatego dobry podział pracy wygląda tak: po polsku szukaj wyjaśnień (dlaczego coś działa właśnie tak), po angielsku szukaj nazw (jak się to nazywa i jak się to dziś pisze). Ściągawka jest ze swojej natury spisem nazw, więc niech będzie angielska i aktualna — cheats.rs plus std.

Jedna rzecz, której nie należy czytać dosłownie z żadnego rysunku: dwie ściągawki z tej strony rysują to samo Vec w różnej kolejności pól (ptr, cap, len u Leviena, ptr, len, capacity na cheats.rs) i żadna nie jest błędna, bo kolejność pól w Vec nie jest przez Rusta gwarantowana. Taki rysunek to odpowiedź na pytanie „z czego składa się ta wartość”, a nie układ bajtów, na którym można polegać — od gwarantowanego układu jest #[repr(C)], którego Vec nie ma.

Szukaj po polsku: ściągawka Rust · rozmieszczenie w pamięci · rust cheat sheet · cheats.rs · rust std collections which to use