Rust Under the Hood

  • Learn how high-level constructs map to assembly
  • Box, Vec, Rc and Arc layout and code generation
  • Async functions transformation into state machines
  • Dynamic dispatch, closures and string internals
  • Loop optimization and SIMD auto-vectorization

A Deep dive into Rust Internals and Generated x86-64 Assembly

This comprehensive guide delves into Rust's core mechanics by examining the assembly code generated by its compiler. Ideal for Rust enthusiasts of all levels, this book offers unique insights into the generated code, memory management, and compiler optimizations.

Discover How Rust Works Under the Hood

Understand Dispatch Mechanisms

Rust Compiler Optimizations and SIMD

Async Programming Insights

Practical Learning

"Rust Under the Hood" pairs insightful explanations with practical examples and exercises at the end of each chapter. Use tools like Compiler Explorer and Rust Playground to reinforce your learning and gain hands-on experience with the generated x86-64 assembly.

Who Should Read This Book?

Book Structure

The book consists of seven parts, each focusing on different aspects of Rust's inner workings:

  1. Introduction to Assembly and Basic Constructs: Start with the basics of assembly language and see how Rust translates simple functions into assembly code.
  2. Control Structures and Enums in Assembly: Explore the assembly output of match and if-else expressions and understand the memory layout of enums.
  3. Data Structures and Memory Management: Investigate the code generation nuances of various data structures and memory management techniques in Rust.
  4. Iteration and Optimization: Compare traditional and functional iteration methods and learn how the Rust compiler optimizes array operations.
  5. Strings, Dispatch, and Recursion: Dive into the inner workings of strings, dynamic dispatch, and recursive function optimization.
  6. Closures and Async/Await: Understand the mechanics of closures and asynchronous functions and how Rust translates them into efficient state machines.
  7. Transformations and Takeaways: Summarize key insights and transformations, providing a solid foundation for future Rust projects.