A quick reference: the C++ thing you reach for, its usual Rust spelling, and
the chapter that explains it. When the translation is not one-to-one, the
chapter is worth reading before you rely on the table.
C++ Rust Chapter
const auto x = 1; / auto x = 1;let x = 1; / let mut x = 1;Values and types
int, int64_t, size_t, uint8_ti32, i64, usize, u8Values and types
Implicit numeric conversions None: as, From, TryFrom Values and types
Signed overflow is UB Panic in debug, wrap in release; wrapping_*, checked_*, saturating_* Values and types
std::array<T, N>[T; N]Values and types
std::pair, std::tuple(A, B)Values and types
struct with constructorstruct + fn new(...) -> SelfValues and types
constexpr value / functionconst / const fnValues and types
static_assert(cond)const _: () = assert!(cond);Macros
cond ? a : bif cond { a } else { b }Values and types
enum classenumEnums and match
std::variant + std::visitenum with data + matchEnums and match
std::optional<T>, nullable T*Option<T>, Option<&T>Enums and match
switchmatch (exhaustive, no fall-through)Enums and match
Structured bindings Patterns: let (a, b) = ...;, if let, let ... else Enums and match
C++ Rust Chapter
Member function / const member function fn f(&mut self) / fn f(&self)Borrowing
Abstract base class, virtual functions Trait, dyn Trait Traits and generics
Template + concept Generic with trait bounds Traits and generics
auto f() returning a hidden typefn f() -> impl TraitTraits and generics
Nested typedef in a traits class Associated type Traits and generics
Inheritance of data Composition (+ traits for behavior) Traits and generics
operator+, operator+=impl Add, impl AddAssignOperators
operator[]Index, IndexMutOperators
operator==, operator<=>#[derive(PartialEq, Eq, PartialOrd, Ord)]Operators
Converting constructor From / IntoOperators
operator<<(ostream&, T)impl Display, #[derive(Debug)]Operators
operator-> on a smart pointerDerefOperators
Lambda Closure (move for by-value capture) Closures and iterators
std::function<R(A)>Box<dyn Fn(A) -> R>Closures and iterators
Callable template parameter impl Fn(A) -> R, F: FnMut(A) -> RClosures and iterators
C++ Rust Chapter
Exceptions Result<T, E> and ?Errors
std::expected<T, E>Result<T, E>Errors
[[nodiscard]]#[must_use] (default on Result)Errors
assert, std::terminateassert!, panic!, .expect("why")Errors
Exception class hierarchy Error enum with thiserror Errors
Catch-all handler at the top anyhow::Result with .context(...)Errors
-fno-exceptionspanic = "abort"Errors
C++ Rust Chapter
std::vector<T>Vec<T>Collections
v.at(i) / v[i]v.get(i) (Option) / v[i] (checked)Collections
Erase-remove idiom v.retain(keep) (keep is a closure)Collections
std::unordered_map, std::mapHashMap, BTreeMapCollections
map[key] (inserting)map.entry(key).or_default()Collections
std::stringString (always UTF-8)Collections
std::filesystem::pathPathBuf, &PathCollections
<algorithm>, rangesIterator adapters: map, filter, zip, fold, collect Closures and iterators
std::threadstd::thread::spawn, std::thread::scopeConcurrency
std::mutex next to the dataMutex<T> containing the dataConcurrency
std::atomic<T>AtomicU32 etc. with OrderingConcurrency
Thread pool / TBB parallel_for rayon: par_iter()Concurrency
std::chrono::steady_clockstd::time::Instant, DurationGame loop
Function-local static OnceLock, LazyLockGame loop
C++ Rust Chapter
CMake + vcpkg/Conan Cargo + crates.io Cargo
Debug / Release cargo build / cargo build --release (profiles)Cargo
add_subdirectoryWorkspace members Assets and build
add_custom_commandbuild.rsAssets and build
namespacemodModules
#include "x.h"mod x; + useModules
public / privatepub / private by defaultModules
#ifdef#[cfg(...)], Cargo featuresMacros
#define macrosmacro_rules!Macros
Reflection macros, code generators #[derive(...)]Macros
GoogleTest / Catch2 #[test], cargo testTesting
Google Benchmark criterion Testing
clang-format / clang-tidy cargo fmt / cargo clippyTesting
Doxygen cargo doc (examples are tested)Testing
C++ Rust Chapter
GLM / DirectXMath glam Math and SIMD
memcpy a struct into a GPU bufferbytemuck::cast_slice on #[derive(Pod)] typesMath and SIMD
GLFW / SDL winit (ApplicationHandler) Game loop
glad / GLEW gl, glowOpenGL
vulkan.h / volkash Vulkan
VMA gpu-allocator, vk-mem Vulkan
Dawn, bgfx, sokol_gfx wgpu wgpu
openxr.h, OpenXR-Hppopenxr-sys, openxrOpenXR
glslc / dxc naga, shaderc, from build.rs wgpu
EnTT, flecs hecs, bevy_ecs ECS
Singletons Context passed as a parameter; ECS resources Game loop
Custom serialization / reflection serde Assets and build
sol2 (Lua) mlua Hot reloading
Symptom Usual fix Chapter
"cannot borrow as mutable because it is also borrowed as immutable" Shorten the first borrow: copy the value out, or finish using it first Borrowing
Pushing to a Vec while holding a reference into it Hold an index instead of a reference Borrowing
Two &mut into the same struct Borrow separate fields (split borrows); destructure let S { a, b } = &mut s; ECS
Two &mut into the same slice split_at_mut, chunks_mut, iter_mutCollections
A struct wants to store a reference to another object Store a handle or index; or own the data Handles and arenas
Objects pointing at each other (graph, parent links) Arena + handles; Rc + Weak only if ownership is truly shared ECS
"borrowed value does not live long enough" Move the owner to an outer scope, or return an owned value Lifetimes
"Rc<...> cannot be sent between threads safely" Arc (and Mutex for mutation)Concurrency
A closure passed to thread::spawn borrows a local move the data in, or use thread::scopeConcurrency
Global mutable state Pass a context; or Mutex, atomics, OnceLock Game loop