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.
Loops
❱
6.2.1.
for
6.2.2.
loop
6.3.
break and continue
❱
6.3.1.
Labels
6.4.
Blocks and Scopes
❱
6.4.1.
Scopes and Shadowing
6.5.
Functions
6.6.
Macros
6.7.
Exercise: Collatz Sequence
❱
6.7.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: &[T]
9.4.
Strings
9.5.
Exercise: Geometry
❱
9.5.1.
Solution
10.
User-Defined Types
❱
10.1.
Named Structs
10.2.
Tuple Structs
10.3.
Enums
10.4.
Static
10.5.
Const
10.6.
Type Aliases
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.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
Day 2: Afternoon
14.
Welcome
15.
Generics
❱
15.1.
Generic Functions
15.2.
Generic Data Types
15.3.
Generic Traits
15.4.
Trait Bounds
15.5.
impl Trait
15.6.
dyn Trait
15.7.
Exercise: Generic min
❱
15.7.1.
Solution
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.
Closures
17.8.
Exercise: ROT13
❱
17.8.1.
Solution
Day 3: Morning
18.
Welcome
19.
Memory Management
❱
19.1.
Review of Program Memory
19.2.
Approaches to Memory Management
19.3.
Ownership
19.4.
Move Semantics
19.5.
Clone
19.6.
Copy Types
19.7.
Drop
19.8.
Exercise: Builder Type
❱
19.8.1.
Solution
20.
Smart Pointers
❱
20.1.
Box<T>
20.2.
Rc
20.3.
Owned Trait Objects
20.4.
Exercise: Binary Tree
❱
20.4.1.
Solution
Day 3: Afternoon
21.
Welcome
22.
Borrowing
❱
22.1.
Borrowing a Value
22.2.
Borrow Checking
22.3.
Borrow Errors
22.4.
Interior Mutability
22.5.
Exercise: Health Statistics
❱
22.5.1.
Solution
23.
Lifetimes
❱
23.1.
Lifetime Annotations
23.2.
Lifetime Elision
23.3.
Struct Lifetimes
23.4.
Exercise: Protobuf Parsing
❱
23.4.1.
Solution
Day 4: Morning
24.
Welcome
25.
Iterators
❱
25.1.
Iterator
25.2.
IntoIterator
25.3.
FromIterator
25.4.
Exercise: Iterator Method Chaining
❱
25.4.1.
Solution
26.
Modules
❱
26.1.
Modules
26.2.
Filesystem Hierarchy
26.3.
Visibility
26.4.
use, super, self
26.5.
Exercise: Modules for a GUI Library
❱
26.5.1.
Solution
27.
Testing
❱
27.1.
Test Modules
27.2.
Other Types of Tests
27.3.
Compiler Lints and Clippy
27.4.
Exercise: Luhn Algorithm
❱
27.4.1.
Solution
Day 4: Afternoon
28.
Welcome
29.
Error Handling
❱
29.1.
Panics
29.2.
Result
29.3.
Try Operator
29.4.
Try Conversions
29.5.
Error Trait
29.6.
thiserror and anyhow
29.7.
Exercise: Rewriting with Result
❱
29.7.1.
Solution
30.
Unsafe Rust
❱
30.1.
Unsafe
30.2.
Dereferencing Raw Pointers
30.3.
Mutable Static Variables
30.4.
Unions
30.5.
Unsafe Functions
30.6.
Unsafe Traits
30.7.
Exercise: FFI Wrapper
❱
30.7.1.
Solution
Android
31.
Welcome
32.
Setup
33.
Build Rules
❱
33.1.
Binary
33.2.
Library
34.
AIDL
❱
34.1.
Birthday Service Tutorial
❱
34.1.1.
Interface
34.1.2.
Service API
34.1.3.
Service
34.1.4.
Server
34.1.5.
Deploy
34.1.6.
Client
34.1.7.
Changing API
34.1.8.
Updating Implementations
34.2.
AIDL Types
❱
34.2.1.
Primitive Types
34.2.2.
Array Types
34.2.3.
Sending Objects
34.2.4.
Parcelables
34.2.5.
Sending Files
35.
Testing
❱
35.1.
GoogleTest
35.2.
Mocking
36.
Logging
37.
Interoperability
❱
37.1.
With C
❱
37.1.1.
Calling C with Bindgen
37.1.2.
Calling Rust from C
37.2.
With C++
❱
37.2.1.
The Bridge Module
37.2.2.
Rust Bridge
37.2.3.
Generated C++
37.2.4.
C++ Bridge
37.2.5.
Shared Types
37.2.6.
Shared Enums
37.2.7.
Rust Error Handling
37.2.8.
C++ Error Handling
37.2.9.
Additional Types
37.2.10.
Building for Android: C++
37.2.11.
Building for Android: Genrules
37.2.12.
Building for Android: Rust
37.3.
With Java
38.
Exercises
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.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.
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 (한국어)
Spanish (Español)
Ukrainian (українська)
Useful crates
We'll go over a few crates which solve some common problems in bare-metal programming.