https://google.github.io/comprehensive-rust/ [ ] 1. Welcome to Comprehensive Rust 2. 1. Running the Course 3. 1. 1.1. Course Structure 2. 1.2. Keyboard Shortcuts 3. 1.3. Translations 4. 2. Using Cargo 5. 1. 2.1. Rust Ecosystem 2. 2.2. Code Samples 3. 2.3. Running Cargo Locally 4. 6. 7. Day 1: Morning 8. 3. Welcome 9. 4. Hello, World 10. 1. 4.1. What is Rust? 2. 4.2. Benefits of Rust 3. 4.3. Playground 11. 5. Types and Values 12. 1. 5.1. Hello, World 2. 5.2. Variables 3. 5.3. Values 4. 5.4. Arithmetic 5. 5.5. Type Inference 6. 5.6. Exercise: Fibonacci 7. 1. 5.6.1. Solution 13. 6. Control Flow Basics 14. 1. 6.1. if Expressions 2. 6.2. Loops 3. 1. 6.2.1. for 2. 6.2.2. loop 4. 6.3. break and continue 5. 1. 6.3.1. Labels 6. 6.4. Blocks and Scopes 7. 1. 6.4.1. Scopes and Shadowing 8. 6.5. Functions 9. 6.6. Macros 10. 6.7. Exercise: Collatz Sequence 11. 1. 6.7.1. Solution 15. 16. Day 1: Afternoon 17. 7. Welcome 18. 8. Tuples and Arrays 19. 1. 8.1. Arrays 2. 8.2. Tuples 3. 8.3. Array Iteration 4. 8.4. Patterns and Destructuring 5. 8.5. Exercise: Nested Arrays 6. 1. 8.5.1. Solution 20. 9. References 21. 1. 9.1. Shared References 2. 9.2. Exclusive References 3. 9.3. Slices: &[T] 4. 9.4. Strings 5. 9.5. Exercise: Geometry 6. 1. 9.5.1. Solution 22. 10. User-Defined Types 23. 1. 10.1. Named Structs 2. 10.2. Tuple Structs 3. 10.3. Enums 4. 10.4. Static 5. 10.5. Const 6. 10.6. Type Aliases 7. 10.7. Exercise: Elevator Events 8. 1. 10.7.1. Solution 2. 24. 25. Day 2: Morning 26. 11. Welcome 27. 12. Pattern Matching 28. 1. 12.1. Matching Values 2. 12.2. Destructuring Structs 3. 12.3. Destructuring Enums 4. 12.4. Let Control Flow 5. 12.5. Exercise: Expression Evaluation 6. 1. 12.5.1. Solution 29. 13. Methods and Traits 30. 1. 13.1. Methods 2. 13.2. Traits 3. 1. 13.2.1. Implementing Traits 2. 13.2.2. Supertraits 3. 13.2.3. Associated Types 4. 13.3. Deriving 5. 13.4. Exercise: Generic Logger 6. 1. 13.4.1. Solution 31. 32. Day 2: Afternoon 33. 14. Welcome 34. 15. Generics 35. 1. 15.1. Generic Functions 2. 15.2. Generic Data Types 3. 15.3. Generic Traits 4. 15.4. Trait Bounds 5. 15.5. impl Trait 6. 15.6. Exercise: Generic min 7. 1. 15.6.1. Solution 36. 16. Standard Library Types 37. 1. 16.1. Standard Library 2. 16.2. Documentation 3. 16.3. Option 4. 16.4. Result 5. 16.5. String 6. 16.6. Vec 7. 16.7. HashMap 8. 16.8. Exercise: Counter 9. 1. 16.8.1. Solution 38. 17. Standard Library Traits 39. 1. 17.1. Comparisons 2. 17.2. Operators 3. 17.3. From and Into 4. 17.4. Casting 5. 17.5. Read and Write 6. 17.6. Default, struct update syntax 7. 17.7. Closures 8. 17.8. Exercise: ROT13 9. 1. 17.8.1. Solution 2. 40. 41. Day 3: Morning 42. 18. Welcome 43. 19. Memory Management 44. 1. 19.1. Review of Program Memory 2. 19.2. Approaches to Memory Management 3. 19.3. Ownership 4. 19.4. Move Semantics 5. 19.5. Clone 6. 19.6. Copy Types 7. 19.7. Drop 8. 19.8. Exercise: Builder Type 9. 1. 19.8.1. Solution 45. 20. Smart Pointers 46. 1. 20.1. Box 2. 20.2. Rc 3. 20.3. Trait Objects 4. 20.4. Exercise: Binary Tree 5. 1. 20.4.1. Solution 47. 48. Day 3: Afternoon 49. 21. Welcome 50. 22. Borrowing 51. 1. 22.1. Borrowing a Value 2. 22.2. Borrow Checking 3. 22.3. Borrow Errors 4. 22.4. Interior Mutability 5. 22.5. Exercise: Health Statistics 6. 1. 22.5.1. Solution 52. 23. Lifetimes 53. 1. 23.1. Lifetime Annotations 2. 23.2. Lifetime Elision 3. 23.3. Struct Lifetimes 4. 23.4. Exercise: Protobuf Parsing 5. 1. 23.4.1. Solution 2. 54. 55. Day 4: Morning 56. 24. Welcome 57. 25. Iterators 58. 1. 25.1. Iterator 2. 25.2. IntoIterator 3. 25.3. FromIterator 4. 25.4. Exercise: Iterator Method Chaining 5. 1. 25.4.1. Solution 59. 26. Modules 60. 1. 26.1. Modules 2. 26.2. Filesystem Hierarchy 3. 26.3. Visibility 4. 26.4. use, super, self 5. 26.5. Exercise: Modules for a GUI Library 6. 1. 26.5.1. Solution 61. 27. Testing 62. 1. 27.1. Test Modules 2. 27.2. Other Types of Tests 3. 27.3. Compiler Lints and Clippy 4. 27.4. Exercise: Luhn Algorithm 5. 1. 27.4.1. Solution 63. 64. Day 4: Afternoon 65. 28. Welcome 66. 29. Error Handling 67. 1. 29.1. Panics 2. 29.2. Try Operator 3. 29.3. Try Conversions 4. 29.4. Error Trait 5. 29.5. thiserror and anyhow 6. 29.6. Exercise: Rewriting with Result 7. 1. 29.6.1. Solution 68. 30. Unsafe Rust 69. 1. 30.1. Unsafe 2. 30.2. Dereferencing Raw Pointers 3. 30.3. Mutable Static Variables 4. 30.4. Unions 5. 30.5. Unsafe Functions 6. 30.6. Unsafe Traits 7. 30.7. Exercise: FFI Wrapper 8. 1. 30.7.1. Solution 70. 71. Android 72. 73. 31. Welcome 74. 32. Setup 75. 33. Build Rules 76. 1. 33.1. Binary 2. 33.2. Library 77. 34. AIDL 78. 1. 34.1. Birthday Service Tutorial 2. 1. 34.1.1. Interface 2. 34.1.2. Service API 3. 34.1.3. Service 4. 34.1.4. Server 5. 34.1.5. Deploy 6. 34.1.6. Client 7. 34.1.7. Changing API 8. 34.1.8. Updating Implementations 3. 34.2. AIDL Types 4. 1. 34.2.1. Primitive Types 2. 34.2.2. Array Types 3. 34.2.3. Sending Objects 4. 34.2.4. Parcelables 5. 34.2.5. Sending Files 79. 35. Testing 80. 1. 35.1. GoogleTest 2. 35.2. Mocking 81. 36. Logging 82. 37. Interoperability 83. 1. 37.1. With C 2. 1. 37.1.1. Calling C with Bindgen 2. 37.1.2. Calling Rust from C 3. 37.2. With C++ 4. 1. 37.2.1. The Bridge Module 2. 37.2.2. Rust Bridge 3. 37.2.3. Generated C++ 4. 37.2.4. C++ Bridge 5. 37.2.5. Shared Types 6. 37.2.6. Shared Enums 7. 37.2.7. Rust Error Handling 8. 37.2.8. C++ Error Handling 9. 37.2.9. Additional Types 10. 37.2.10. Building for Android: C++ 11. 37.2.11. Building for Android: Genrules 12. 37.2.12. Building for Android: Rust 5. 37.3. With Java 84. 38. Exercises 85. 86. Chromium 87. 88. 39. Welcome 89. 40. Setup 90. 41. Comparing Chromium and Cargo Ecosystems 91. 42. Policy 92. 43. Build Rules 93. 1. 43.1. Unsafe Code 2. 43.2. Depending on Rust Code from Chromium C++ 3. 43.3. Visual Studio Code 4. 43.4. Exercise 94. 44. Testing 95. 1. 44.1. rust_gtest_interop Library 2. 44.2. GN Rules for Rust Tests 3. 44.3. chromium::import! Macro 4. 44.4. Exercise 96. 45. Interoperability with C++ 97. 1. 45.1. Example Bindings 2. 45.2. Limitations of CXX 3. 45.3. CXX Error Handling 4. 1. 45.3.1. Error Handling: QR Example 2. 45.3.2. Error Handling: PNG Example 5. 45.4. Using CXX in Chromium 6. 45.5. Exercise 98. 46. Adding Third Party Crates 99. 1. 46.1. Configuring Cargo.toml 2. 46.2. Configuring gnrt_config.toml 3. 46.3. Downloading Crates 4. 46.4. Generating gn Build Rules 5. 46.5. Resolving Problems 6. 1. 46.5.1. Build Scripts Which Generate Code 2. 46.5.2. Build Scripts Which Build C++ or Take Arbitrary Actions 7. 46.6. Depending on a Crate 8. 46.7. Reviews and Audits 9. 46.8. Checking into Chromium Source Code 10. 46.9. Keeping Crates Up to Date 11. 46.10. Exercise 100. 47. Bringing It Together - Exercise 101. 48. Exercise Solutions 102. 103. Bare Metal: Morning 104. 105. 49. Welcome 106. 50. no_std 107. 1. 50.1. A Minimal Example 2. 50.2. alloc 108. 51. Microcontrollers 109. 1. 51.1. Raw MMIO 2. 51.2. PACs 3. 51.3. HAL Crates 4. 51.4. Board Support Crates 5. 51.5. The Type State Pattern 6. 51.6. embedded-hal 7. 51.7. probe-rs and cargo-embed 8. 1. 51.7.1. Debugging 9. 51.8. Other Projects 110. 52. Exercises 111. 1. 52.1. Compass 2. 52.2. Solutions 112. 113. Bare Metal: Afternoon 114. 53. Application Processors 115. 1. 53.1. Getting Ready to Rust 2. 53.2. Inline Assembly 3. 53.3. MMIO 4. 53.4. Let's Write a UART Driver 5. 1. 53.4.1. More Traits 6. 53.5. A Better UART Driver 7. 1. 53.5.1. Bitflags 2. 53.5.2. Multiple Registers 3. 53.5.3. Driver 4. 53.5.4. Using It 8. 53.6. Logging 9. 1. 53.6.1. Using It 10. 53.7. Exceptions 11. 53.8. Other Projects 116. 54. Useful Crates 117. 1. 54.1. zerocopy 2. 54.2. aarch64-paging 3. 54.3. buddy_system_allocator 4. 54.4. tinyvec 5. 54.5. spin 118. 55. Android 119. 1. 55.1. vmbase 120. 56. Exercises 121. 1. 56.1. RTC Driver 2. 56.2. Solutions 122. 123. Concurrency: Morning 124. 125. 57. Welcome 126. 58. Threads 127. 1. 58.1. Plain Threads 2. 58.2. Scoped Threads 128. 59. Channels 129. 1. 59.1. Senders and Reveivers 2. 59.2. Unbounded Channels 3. 59.3. Bounded Channels 130. 60. Send and Sync 131. 1. 60.1. Marker Traits 2. 60.2. Send 3. 60.3. Sync 4. 60.4. Examples 132. 61. Shared State 133. 1. 61.1. Arc 2. 61.2. Mutex 3. 61.3. Example 134. 62. Exercises 135. 1. 62.1. Dining Philosophers 2. 62.2. Multi-threaded Link Checker 3. 62.3. Solutions 136. 137. Concurrency: Afternoon 138. 63. Welcome 139. 64. Async Basics 140. 1. 64.1. async/await 2. 64.2. Futures 3. 64.3. Runtimes 4. 1. 64.3.1. Tokio 5. 64.4. Tasks 141. 65. Channels and Control Flow 142. 1. 65.1. Async Channels 2. 65.2. Join 3. 65.3. Select 143. 66. Pitfalls 144. 1. 66.1. Blocking the Executor 2. 66.2. Pin 3. 66.3. Async Traits 4. 66.4. Cancellation 145. 67. Exercises 146. 1. 67.1. Dining Philosophers 2. 67.2. Broadcast Chat Application 3. 67.3. Solutions 147. 148. Final Words 149. 150. 68. Thanks! 151. 69. Glossary 152. 70. Other Resources 153. 71. Credits * Light * Rust * Coal * Navy * Ayu Comprehensive Rust * English * Brazilian Portuguese (Portugues do Brasil) * Chinese Simplified (Yi Yu ) * Chinese Traditional (Han Yu ) * Korean (hangugeo) * Spanish (Espanol) [ ] Welcome to Comprehensive Rust Build workflow GitHub contributors GitHub stars This is a free Rust course developed by the Android team at Google. The course covers the full spectrum of Rust, from basic syntax to advanced topics like generics and error handling. The latest version of the course can be found at https:// google.github.io/comprehensive-rust/. If you are reading somewhere else, please check there for updates. The course is also available as a PDF. The goal of the course is to teach you Rust. We assume you don't know anything about Rust and hope to: * Give you a comprehensive understanding of the Rust syntax and language. * Enable you to modify existing programs and write new programs in Rust. * Show you common Rust idioms. We call the first four course days Rust Fundamentals. Building on this, you're invited to dive into one or more specialized topics: * Android: a half-day course on using Rust for Android platform development (AOSP). This includes interoperability with C, C++, and Java. * Chromium: a half-day course on using Rust within Chromium based browsers. This includes interoperability with C++ and how to include third-party crates in Chromium. * Bare-metal: a whole-day class on using Rust for bare-metal (embedded) development. Both microcontrollers and application processors are covered. * Concurrency: a whole-day class on concurrency in Rust. We cover both classical concurrency (preemptively scheduling using threads and mutexes) and async/await concurrency (cooperative multitasking using futures). Non-Goals Rust is a large language and we won't be able to cover all of it in a few days. Some non-goals of this course are: * Learning how to develop macros: please see Chapter 19.5 in the Rust Book and Rust by Example instead. Assumptions The course assumes that you already know how to program. Rust is a statically-typed language and we will sometimes make comparisons with C and C++ to better explain or contrast the Rust approach. If you know how to program in a dynamically-typed language such as Python or JavaScript, then you will be able to follow along just fine too. This is an example of a speaker note. We will use these to add additional information to the slides. This could be key points which the instructor should cover as well as answers to typical questions which come up in class.