Welcome to Comprehensive Rust 🦀
1.
Running the Course
❱
1.1.
Course Structure
1.2.
Keyboard Shortcuts
1.3.
Translations
2.
Using Cargo
❱
2.1.
Rust Ecosystem
2.2.
Code Samples
2.3.
Running Cargo Locally
Day 1: Morning
3.
Welcome
4.
Hello, World
❱
4.1.
What is Rust?
4.2.
Benefits of Rust
4.3.
Playground
5.
Types and Values
❱
5.1.
Hello, World
5.2.
Variables
5.3.
Values
5.4.
Arithmetic
5.5.
Type Inference
5.6.
Exercise: Fibonacci
❱
5.6.1.
Solution
6.
Control Flow Basics
❱
6.1.
if Expressions
6.2.
match Expressions
6.3.
Loops
❱
6.3.1.
for
6.3.2.
loop
6.4.
break and continue
❱
6.4.1.
Labels
6.5.
Blocks and Scopes
❱
6.5.1.
Scopes and Shadowing
6.6.
Functions
6.7.
Macros
6.8.
Exercise: Collatz Sequence
❱
6.8.1.
Solution
Day 1: Afternoon
7.
Welcome
8.
Tuples and Arrays
❱
8.1.
Arrays
8.2.
Tuples
8.3.
Array Iteration
8.4.
Patterns and Destructuring
8.5.
Exercise: Nested Arrays
❱
8.5.1.
Solution
9.
References
❱
9.1.
Shared References
9.2.
Exclusive References
9.3.
Slices
9.4.
Strings
9.5.
Reference Validity
9.6.
Exercise: Geometry
❱
9.6.1.
Solution
10.
User-Defined Types
❱
10.1.
Named Structs
10.2.
Tuple Structs
10.3.
Enums
10.4.
Type Aliases
10.5.
Const
10.6.
Static
10.7.
Exercise: Elevator Events
❱
10.7.1.
Solution
Day 2: Morning
11.
Welcome
12.
Pattern Matching
❱
12.1.
Matching Values
12.2.
Destructuring Structs
12.3.
Destructuring Enums
12.4.
Let Control Flow
❱
12.4.1.
if let Expressions
12.4.2.
while let Statements
12.4.3.
let else
12.5.
Exercise: Expression Evaluation
❱
12.5.1.
Solution
13.
Methods and Traits
❱
13.1.
Methods
13.2.
Traits
❱
13.2.1.
Implementing Traits
13.2.2.
Supertraits
13.2.3.
Associated Types
13.3.
Deriving
13.4.
Exercise: Generic Logger
❱
13.4.1.
Solution
14.
Generics
❱
14.1.
Generic Functions
14.2.
Generic Data Types
14.3.
Generic Traits
14.4.
Trait Bounds
14.5.
impl Trait
14.6.
dyn Trait
14.7.
Exercise: Generic min
❱
14.7.1.
Solution
Day 2: Afternoon
15.
Welcome
16.
Standard Library Types
❱
16.1.
Standard Library
16.2.
Documentation
16.3.
Option
16.4.
Result
16.5.
String
16.6.
Vec
16.7.
HashMap
16.8.
Exercise: Counter
❱
16.8.1.
Solution
17.
Standard Library Traits
❱
17.1.
Comparisons
17.2.
Operators
17.3.
From and Into
17.4.
Casting
17.5.
Read and Write
17.6.
Default, struct update syntax
17.7.
Exercise: ROT13
❱
17.7.1.
Solution
18.
Closures
❱
18.1.
Closure Syntax
18.2.
Capturing
18.3.
Closure Traits
18.4.
Exercise: Log Filter
❱
18.4.1.
Solution
Day 3: Morning
19.
Welcome
20.
Memory Management
❱
20.1.
Review of Program Memory
20.2.
Approaches to Memory Management
20.3.
Ownership
20.4.
Move Semantics
20.5.
Clone
20.6.
Copy Types
20.7.
Drop
20.8.
Exercise: Builder Type
❱
20.8.1.
Solution
21.
Smart Pointers
❱
21.1.
Box<T>
21.2.
Rc
21.3.
Owned Trait Objects
21.4.
Exercise: Binary Tree
❱
21.4.1.
Solution
Day 3: Afternoon
22.
Welcome
23.
Borrowing
❱
23.1.
Borrowing a Value
23.2.
Borrow Checking
23.3.
Borrow Errors
23.4.
Interior Mutability
❱
23.4.1.
Cell
23.4.2.
RefCell
23.5.
Exercise: Health Statistics
❱
23.5.1.
Solution
24.
Lifetimes
❱
24.1.
Lifetime Annotations
24.2.
Lifetime Elision
24.3.
Struct Lifetimes
24.4.
Exercise: Protobuf Parsing
❱
24.4.1.
Solution
Day 4: Morning
25.
Welcome
26.
Iterators
❱
26.1.
Motivation
26.2.
Iterator Trait
26.3.
Iterator Helper Methods
26.4.
collect
26.5.
IntoIterator
26.6.
Exercise: Iterator Method Chaining
❱
26.6.1.
Solution
27.
Modules
❱
27.1.
Modules
27.2.
Filesystem Hierarchy
27.3.
Visibility
27.4.
Encapsulation
27.5.
use, super, self
27.6.
Exercise: Modules for a GUI Library
❱
27.6.1.
Solution
28.
Testing
❱
28.1.
Unit Tests
28.2.
Other Types of Tests
28.3.
Compiler Lints and Clippy
28.4.
Exercise: Luhn Algorithm
❱
28.4.1.
Solution
Day 4: Afternoon
29.
Welcome
30.
Error Handling
❱
30.1.
Panics
30.2.
Result
30.3.
Try Operator
30.4.
Try Conversions
30.5.
Error Trait
30.6.
thiserror
30.7.
anyhow
30.8.
Exercise: Rewriting with Result
❱
30.8.1.
Solution
31.
Unsafe Rust
❱
31.1.
Unsafe
31.2.
Dereferencing Raw Pointers
31.3.
Mutable Static Variables
31.4.
Unions
31.5.
Unsafe Functions
31.6.
Unsafe Traits
31.7.
Exercise: FFI Wrapper
❱
31.7.1.
Solution
Android
32.
Welcome
33.
Setup
34.
Build Rules
❱
34.1.
Binary
34.2.
Library
35.
AIDL
❱
35.1.
Birthday Service Tutorial
❱
35.1.1.
Interface
35.1.2.
Service API
35.1.3.
Service
35.1.4.
Server
35.1.5.
Deploy
35.1.6.
Client
35.1.7.
Changing API
35.1.8.
Updating Implementations
35.2.
AIDL Types
❱
35.2.1.
Primitive Types
35.2.2.
Array Types
35.2.3.
Sending Objects
35.2.4.
Parcelables
35.2.5.
Sending Files
36.
Testing
❱
36.1.
GoogleTest
36.2.
Mocking
37.
Logging
38.
Interoperability
❱
38.1.
With C
❱
38.1.1.
Calling C with Bindgen
38.1.2.
Calling Rust from C
38.2.
With C++
❱
38.2.1.
The Bridge Module
38.2.2.
Rust Bridge
38.2.3.
Generated C++
38.2.4.
C++ Bridge
38.2.5.
Shared Types
38.2.6.
Shared Enums
38.2.7.
Rust Error Handling
38.2.8.
C++ Error Handling
38.2.9.
Additional Types
38.2.10.
Building for Android: C++
38.2.11.
Building for Android: Genrules
38.2.12.
Building for Android: Rust
38.3.
With Java
Chromium
39.
Welcome
40.
Setup
41.
Comparing Chromium and Cargo Ecosystems
42.
Policy
43.
Build Rules
❱
43.1.
Unsafe Code
43.2.
Depending on Rust Code from Chromium C++
43.3.
Visual Studio Code
43.4.
Exercise
44.
Testing
❱
44.1.
rust_gtest_interop Library
44.2.
GN Rules for Rust Tests
44.3.
chromium::import! Macro
44.4.
Exercise
45.
Interoperability with C++
❱
45.1.
Example Bindings
45.2.
Limitations of CXX
45.3.
CXX Error Handling
❱
45.3.1.
Error Handling: QR Example
45.3.2.
Error Handling: PNG Example
45.4.
Using CXX in Chromium
45.5.
Exercise
46.
Adding Third Party Crates
❱
46.1.
Configuring Cargo.toml
46.2.
Configuring gnrt_config.toml
46.3.
Downloading Crates
46.4.
Generating gn Build Rules
46.5.
Resolving Problems
❱
46.5.1.
Build Scripts Which Generate Code
46.5.2.
Build Scripts Which Build C++ or Take Arbitrary Actions
46.6.
Depending on a Crate
46.7.
Reviews and Audits
46.8.
Checking into Chromium Source Code
46.9.
Keeping Crates Up to Date
46.10.
Exercise
47.
Bringing It Together - Exercise
48.
Exercise Solutions
Bare Metal: Morning
49.
Welcome
50.
no_std
❱
50.1.
A Minimal Example
50.2.
alloc
51.
Microcontrollers
❱
51.1.
Raw MMIO
51.2.
PACs
51.3.
HAL Crates
51.4.
Board Support Crates
51.5.
The Type State Pattern
51.6.
embedded-hal
51.7.
probe-rs and cargo-embed
❱
51.7.1.
Debugging
51.8.
Other Projects
52.
Exercises
❱
52.1.
Compass
52.2.
Solutions
Bare Metal: Afternoon
53.
Application Processors
❱
53.1.
Getting Ready to Rust
53.2.
Inline Assembly
53.3.
MMIO
53.4.
Let's Write a UART Driver
❱
53.4.1.
More Traits
53.4.2.
Using It
53.5.
A Better UART Driver
❱
53.5.1.
Bitflags
53.5.2.
Multiple Registers
53.5.3.
Driver
53.5.4.
Using It
53.6.
Logging
❱
53.6.1.
Using It
53.7.
Exceptions
53.8.
Other Projects
54.
Useful Crates
❱
54.1.
zerocopy
54.2.
aarch64-paging
54.3.
buddy_system_allocator
54.4.
tinyvec
54.5.
spin
55.
Bare-Metal on Android
❱
55.1.
vmbase
56.
Exercises
❱
56.1.
RTC Driver
56.2.
Solutions
Concurrency: Morning
57.
Welcome
58.
Threads
❱
58.1.
Plain Threads
58.2.
Scoped Threads
59.
Channels
❱
59.1.
Senders and Receivers
59.2.
Unbounded Channels
59.3.
Bounded Channels
60.
Send and Sync
❱
60.1.
Marker Traits
60.2.
Send
60.3.
Sync
60.4.
Examples
61.
Shared State
❱
61.1.
Arc
61.2.
Mutex
61.3.
Example
62.
Exercises
❱
62.1.
Dining Philosophers
62.2.
Multi-threaded Link Checker
62.3.
Solutions
Concurrency: Afternoon
63.
Welcome
64.
Async Basics
❱
64.1.
async/await
64.2.
Futures
64.3.
Runtimes
❱
64.3.1.
Tokio
64.4.
Tasks
65.
Channels and Control Flow
❱
65.1.
Async Channels
65.2.
Join
65.3.
Select
66.
Pitfalls
❱
66.1.
Blocking the Executor
66.2.
Pin
66.3.
Async Traits
66.4.
Cancellation
67.
Exercises
❱
67.1.
Dining Philosophers
67.2.
Broadcast Chat Application
67.3.
Solutions
Final Words
68.
Thanks!
69.
Glossary
70.
Other Resources
71.
Credits
Light
Rust
Coal
Navy
Ayu
Comprehensive Rust 🦀
English
Brazilian Portuguese (Português do Brasil)
Chinese Simplified (汉语)
Chinese Traditional (漢語)
Japanese (日本語)
Korean (한국어)
Farsi (فارسی)
Spanish (Español)
Ukrainian (українська)
Exercise Solutions
Solutions to the Chromium exercises can be found in
this series of CLs
.