1. Welcome to Comprehensive Rust 🦀
  2. Running the Course
    ❱
    1. Course Structure
    2. Keyboard Shortcuts
    3. Translations
  3. Using Cargo
    ❱
    1. Rust Ecosystem
    2. Code Samples
    3. Running Cargo Locally
  4. Day 1: Morning
  5. Welcome
  6. Hello, World
    ❱
    1. What is Rust?
    2. Benefits of Rust
    3. Playground
  7. Types and Values
    ❱
    1. Hello, World
    2. Variables
    3. Values
    4. Arithmetic
    5. Type Inference
    6. Exercise: Fibonacci
      ❱
      1. Solution
  8. Control Flow Basics
    ❱
    1. Blocks and Scopes
    2. if Expressions
    3. match Expressions
    4. Loops
      ❱
      1. for
      2. loop
    5. break and continue
      ❱
      1. Labels
    6. Functions
    7. Macros
    8. Exercise: Collatz Sequence
      ❱
      1. Solution
  9. Day 1: Afternoon
  10. Welcome
  11. Tuples and Arrays
    ❱
    1. Arrays
    2. Tuples
    3. Array Iteration
    4. Patterns and Destructuring
    5. Exercise: Nested Arrays
      ❱
      1. Solution
  12. References
    ❱
    1. Shared References
    2. Exclusive References
    3. Slices
    4. Strings
    5. Reference Validity
    6. Exercise: Geometry
      ❱
      1. Solution
  13. User-Defined Types
    ❱
    1. Named Structs
    2. Tuple Structs
    3. Enums
    4. Type Aliases
    5. Const
    6. Static
    7. Exercise: Elevator Events
      ❱
      1. Solution
  14. Day 2: Morning
  15. Welcome
  16. Pattern Matching
    ❱
    1. Irrefutable Patterns
    2. Matching Values
    3. Destructuring Structs
    4. Destructuring Enums
    5. Let Control Flow
      ❱
      1. if let Expressions
      2. while let Statements
      3. let else
    6. Exercise: Expression Evaluation
      ❱
      1. Solution
  17. Methods and Traits
    ❱
    1. Methods
    2. Traits
      ❱
      1. Implementing Traits
      2. Supertraits
      3. Associated Types
    3. Deriving
    4. Exercise: Logger Trait
      ❱
      1. Solution
  18. Generics
    ❱
    1. Generic Functions
    2. Trait Bounds
    3. Generic Data Types
    4. Generic Traits
    5. impl Trait
    6. dyn Trait
    7. Exercise: Generic min
      ❱
      1. Solution
  19. Day 2: Afternoon
  20. Welcome
  21. Closures
    ❱
    1. Closure Syntax
    2. Capturing
    3. Closure Traits
    4. Exercise: Log Filter
      ❱
      1. Solution
  22. Standard Library Types
    ❱
    1. Standard Library
    2. Documentation
    3. Option
    4. Result
    5. String
    6. Vec
    7. HashMap
    8. Exercise: Counter
      ❱
      1. Solution
  23. Standard Library Traits
    ❱
    1. Comparisons
    2. Operators
    3. From and Into
    4. Casting
    5. Read and Write
    6. Default, struct update syntax
    7. Exercise: ROT13
      ❱
      1. Solution
  24. Day 3: Morning
  25. Welcome
  26. Memory Management
    ❱
    1. Review of Program Memory
    2. Approaches to Memory Management
    3. Ownership
    4. Move Semantics
    5. Clone
    6. Copy Types
    7. Drop
    8. Exercise: Builder Type
      ❱
      1. Solution
  27. Smart Pointers
    ❱
    1. Box<T>
    2. Rc
    3. Owned Trait Objects
    4. Exercise: Binary Tree
      ❱
      1. Solution
  28. Day 3: Afternoon
  29. Welcome
  30. Borrowing
    ❱
    1. Borrowing a Value
    2. Borrow Checking
    3. Borrow Errors
    4. Interior Mutability
      ❱
      1. Cell
      2. RefCell
    5. Exercise: Wizard's Inventory
      ❱
      1. Solution
  31. Lifetimes
    ❱
    1. Borrowing and Functions
    2. Returning Borrows
    3. Multiple Borrows
    4. Borrow Both
    5. Borrow One
    6. Lifetime Elision
    7. Lifetimes in Data Structures
    8. Exercise: Protobuf Parsing
      ❱
      1. Solution
  32. Day 4: Morning
  33. Welcome
  34. Iterators
    ❱
    1. for Review
    2. Motivation
    3. Iterator Trait
    4. Iterator Helper Methods
    5. enumerate
    6. collect
    7. IntoIterator
    8. IntoIterator On References
    9. Exercise: Iterator Method Chaining
      ❱
      1. Solution
  35. Modules
    ❱
    1. Modules
    2. Filesystem Hierarchy
    3. Visibility
    4. Encapsulation
    5. use, super, self
    6. Exercise: Modules for a GUI Library
      ❱
      1. Solution
  36. Testing
    ❱
    1. Unit Tests
    2. Other Types of Tests
    3. Compiler Lints and Clippy
    4. Exercise: Luhn Algorithm
      ❱
      1. Solution
  37. Day 4: Afternoon
  38. Welcome
  39. Error Handling
    ❱
    1. Panics
    2. Result
    3. Try Operator
    4. Try Conversions
    5. Error Type Compatibility
    6. thiserror
    7. Dynamic Error Types
    8. anyhow
    9. Exercise: Rewriting with Result
      ❱
      1. Solution
  40. Unsafe Rust
    ❱
    1. Unsafe
    2. Dereferencing Raw Pointers
    3. Mutable Static Variables
    4. Unions
    5. Unsafe Functions
      ❱
      1. Unsafe Rust Functions
      2. Unsafe External Functions
      3. Calling Unsafe Functions
    6. Unsafe Traits
    7. Exercise: FFI Wrapper
      ❱
      1. Solution
  41. Android
  42. Welcome
  43. Setup
  44. Build Rules
    ❱
    1. Binary
    2. Library
  45. AIDL
    ❱
    1. Birthday Service Tutorial
      ❱
      1. Interface
      2. Service API
      3. Service
      4. Server
      5. Deploy
      6. Client
      7. Changing API
      8. Updating Implementations
    2. AIDL Types
      ❱
      1. Primitive Types
      2. Array Types
      3. Sending Objects
      4. Parcelables
      5. Sending Files
  46. Testing
    ❱
    1. GoogleTest
    2. Mocking
  47. Logging
  48. Interoperability
    ❱
    1. With C
      ❱
      1. A Simple C Library
      2. Bindgen
      3. Running Our Binary
      4. A Simple Rust Library
      5. Calling Rust from C
    2. With C++
      ❱
      1. The Bridge Module
      2. Rust Bridge
      3. Generated C++
      4. C++ Bridge
      5. Shared Types
      6. Shared Enums
      7. Rust Error Handling
      8. C++ Error Handling
      9. Additional Types
      10. Building for Android: Genrules
      11. Building for Android: C++
      12. Building for Android: Rust
    3. With Java
  49. Chromium
  50. Welcome
  51. Setup
  52. Comparing Chromium and Cargo Ecosystems
  53. Policy
  54. Build Rules
    ❱
    1. Unsafe Code
    2. Depending on Rust Code from Chromium C++
    3. Visual Studio Code
    4. Exercise
  55. Testing
    ❱
    1. rust_gtest_interop Library
    2. GN Rules for Rust Tests
    3. chromium::import! Macro
    4. Exercise
  56. Interoperability with C++
    ❱
    1. Example Bindings
    2. Limitations of CXX
    3. CXX Error Handling
      ❱
      1. Error Handling: QR Example
      2. Error Handling: PNG Example
    4. Using CXX in Chromium
    5. Exercise
  57. Adding Third Party Crates
    ❱
    1. Configuring Cargo.toml
    2. Configuring gnrt_config.toml
    3. Downloading Crates
    4. Generating gn Build Rules
    5. Resolving Problems
      ❱
      1. Build Scripts Which Generate Code
      2. Build Scripts Which Build C++ or Take Arbitrary Actions
    6. Depending on a Crate
    7. Reviews and Audits
    8. Checking into Chromium Source Code
    9. Keeping Crates Up to Date
    10. Exercise
  58. Bringing It Together - Exercise
  59. Exercise Solutions
  60. Bare Metal: Morning
  61. Welcome
  62. no_std
    ❱
    1. A Minimal Example
    2. alloc
  63. Microcontrollers
    ❱
    1. Raw MMIO
    2. PACs
    3. HAL Crates
    4. Board Support Crates
    5. The Type State Pattern
    6. embedded-hal
    7. probe-rs and cargo-embed
      ❱
      1. Debugging
    8. Other Projects
  64. Exercises
    ❱
    1. Compass
    2. Solutions
  65. Bare Metal: Afternoon
  66. Application Processors
    ❱
    1. Getting Ready to Rust
    2. Inline Assembly
    3. MMIO
    4. Let's Write a UART Driver
      ❱
      1. More Traits
      2. Using It
    5. A Better UART Driver
      ❱
      1. Bitflags
      2. Multiple Registers
      3. Driver
    6. safe-mmio
      ❱
      1. Driver
      2. Using It
    7. Logging
      ❱
      1. Using It
    8. Exceptions
    9. aarch64-rt
      ❱
      1. Exceptions
    10. Other Projects
  67. Useful Crates
    ❱
    1. zerocopy
    2. aarch64-paging
    3. buddy_system_allocator
    4. tinyvec
    5. spin
  68. Bare-Metal on Android
    ❱
    1. vmbase
  69. Exercises
    ❱
    1. RTC Driver
    2. Solutions
  70. Concurrency: Morning
  71. Welcome
  72. Threads
    ❱
    1. Plain Threads
    2. Scoped Threads
  73. Channels
    ❱
    1. Senders and Receivers
    2. Unbounded Channels
    3. Bounded Channels
  74. Send and Sync
    ❱
    1. Marker Traits
    2. Send
    3. Sync
    4. Examples
  75. Shared State
    ❱
    1. Arc
    2. Mutex
    3. Example
  76. Exercises
    ❱
    1. Dining Philosophers
    2. Multi-threaded Link Checker
    3. Solutions
  77. Concurrency: Afternoon
  78. Welcome
  79. Async Basics
    ❱
    1. async/await
    2. Futures
    3. State Machine
    4. Runtimes
      ❱
      1. Tokio
    5. Tasks
  80. Channels and Control Flow
    ❱
    1. Async Channels
    2. Join
    3. Select
  81. Pitfalls
    ❱
    1. Blocking the Executor
    2. Pin
    3. Async Traits
    4. Cancellation
  82. Exercises
    ❱
    1. Dining Philosophers
    2. Broadcast Chat Application
    3. Solutions
  83. Idiomatic Rust
  84. Welcome
  85. Foundations of API Design
    ❱
    1. Meaningful Doc Comments
      ❱
      1. Who Are You Writing For?
      2. Library vs Application docs
      3. Anatomy of a Doc Comment
      4. Name Drop and Signpost
      5. Avoid Redundancy
      6. Name and Signature are Not Enough
      7. What and Why, not How and Where
      8. Exercise
    2. Predictable API
      ❱
      1. Naming conventions
        ❱
        1. New
        2. Is
        3. Mut
        4. With: Constructor
        5. With: Copy-and-change
        6. With: Closures
        7. Try
        8. From
        9. Into
        10. To
        11. As and Ref
        12. By
        13. Exercise
      2. Implementing Common Traits
        ❱
        1. Debug
        2. Display
        3. PartialEq and Eq
        4. PartialOrd and Ord
        5. Hash
        6. Clone
        7. Copy
        8. From and Into
        9. TryFrom and TryInto
        10. Serialize and Deserialize
  86. Leveraging the Type System
    ❱
    1. Newtype Pattern
      ❱
      1. Semantic Confusion
      2. Enforce Invariants
      3. Is It Encapsulated?
    2. RAII
      ❱
      1. Drop Skipped
      2. Mutex
      3. Drop Guards
      4. Drop Bomb
      5. Drop Bomb Forget
      6. forget and drop functions
      7. Scope Guard
      8. Drop Option
    3. Extension Traits
      ❱
      1. Orphan Rule
      2. Extending Foreign Types
      3. Method Resolution Conflicts
      4. Trait Method Conflicts
      5. Extending Other Traits
      6. Should I Define An Extension Trait?
    4. Typestate Pattern
      ❱
      1. Typestate Pattern Example
      2. Beyond Simple Typestate
      3. Typestate Pattern with Generics
        ❱
        1. Serializer: implement Root
        2. Serializer: implement Struct
        3. Serializer: implement Property
        4. Serializer: Complete implementation
    5. Borrow checking invariants
      ❱
      1. Lifetimes and Borrows: the Abstract Rules
      2. Single-use values
      3. Mutually Exclusive References / "Aliasing XOR Mutability"
      4. PhantomData and Types
      5. PhantomData and Types (implementation)
      6. PhantomData: Lifetimes for External Resources
      7. PhantomData: OwnedFd & BorrowedFd
    6. Token Types
      ❱
      1. Permission Tokens
      2. Token Types with Data: Mutex Guards
      3. Branded pt 1: Variable-specific tokens
      4. Branded pt 2: PhantomData and Lifetime Subtyping
      5. Branded pt 3: Implementation
      6. Branded pt 4: Branded types in action.
  87. Polymorphism
    ❱
    1. What is Polymorphism?
    2. Kinds of Polymorphism
    3. Generics
      ❱
      1. Trait Bounds
      2. Deriving Traits
      3. Default Implementations
      4. Supertraits
      5. Blanket Implementations
      6. Conditional Methods
      7. Statically Sized and Dynamically Sized types
      8. Monomorphization and Binary Size
      9. Sealed Traits
    4. Enums
      ❱
      1. Inspecting Enums
      2. Heterogeneous Collections
      3. Re-exposing Traits
    5. dyn
      ❱
      1. Dyn Compatibility
      2. Generics vs Trait Objects
      3. Limits of Trait Objects
      4. Heterogeneous Collections
      5. The Any Trait
      6. Sealing with Enums
    6. Enums vs dyn
  88. From OOP to Rust
    ❱
    1. Inheritance
    2. Why no Inheritance in Rust?
    3. Inheritance from Rust's Perspective
    4. "Inheritance" in Rust and Supertraits
    5. Composition over Inheritance
    6. Problem solving: Break Down the Problem
  89. Unsafe
  90. Welcome
  91. Setup
  92. Introduction
    ❱
    1. Defining Unsafe Rust
    2. Purpose of the unsafe keyword
    3. Two roles of the unsafe keyword
    4. Warm Up Examples
      ❱
      1. Using an unsafe block
      2. Defining an unsafe function
      3. Implementing an unsafe trait
      4. Defining an unsafe trait
    5. Characteristics of Unsafe Rust
      ❱
      1. Dangerous
      2. Sometimes necessary
      3. Sometimes useful
    6. Responsibility shift
    7. Stronger development workflow required
    8. Example: may_overflow
  93. Safety Preconditions
    ❱
    1. Common Preconditions
      ❱
      1. Getter example
    2. Semantic preconditions
      ❱
      1. Example: u8 to bool
    3. Determining preconditions
      ❱
      1. Example: references
    4. Defining your own preconditions
      ❱
      1. Example: ASCII Type
  94. Rules of the game
    ❱
    1. Rust is sound
    2. Copying memory
      ❱
      1. Safe Rust
      2. Encapsulated Unsafe Rust
      3. Exposed Unsafe Rust
      4. Documented safety preconditions
      5. Crying Wolf
    3. 3 shapes of sound Rust
    4. Soundness Proof
      ❱
      1. Soundness
      2. Corollary
      3. Unsoundness
  95. Memory Lifecycle
  96. Initialization
    ❱
    1. MaybeUninit
      ❱
      1. Arrays of uninit
      2. MaybeUninit::zeroed()
      3. ptr::write vs assignment
    2. How to initialize memory
    3. Partial initialization
  97. Pinning
    ❱
    1. What pinning is
    2. What a move is
    3. Definition of Pin
    4. Why it's difficult
    5. Unpin trait
    6. PhantomPinned
    7. Self-Referential Buffer Example
      ❱
      1. C++ implementation
      2. Modeled in Rust
        ❱
        1. With a raw pointer
        2. With an integer offset
        3. With Pin<Ptr>
    8. Pin<Ptr> and Drop
      ❱
      1. Worked Example
  98. FFI
    ❱
    1. Language Interop
    2. Strategies
    3. Consideration: Type Safety
    4. Language differences
      ❱
      1. Different representations
      2. Different semantics
      3. Rust ↔ C
      4. C++ ↔ C
      5. Rust ↔ C++
    5. abs(3)
    6. rand(3)
    7. Exercise:C library
    8. Exercise: C++ library
  99. Final Words
  100. Thanks!
  101. Glossary
  102. Other Resources
  103. Credits