Lab: Advanced Rust
Consolidate async, concurrency, Cargo, testing, and macro knowledge through scenario-based quiz questions.
- Reason about async vs thread trade-offs
- Apply Cargo features and workspace knowledge to real scenarios
- Plan a test strategy for a module
- Identify correct macro patterns
This lab covers the advanced module through scenario questions. Work through each one before reading the explanation — that gap between "I think…" and "because…" is where learning happens.
Part 1: Async vs threads
Knowledge check
- 1.Your program needs to compress 8 large files as fast as possible. The system has 8 CPU cores and the compression is CPU-bound. Which approach gives the best performance?
- 2.Your web server handles 5,000 concurrent connections. Most of the time is spent waiting for database queries. Which model is more resource-efficient?
- 3.In Rust, you can mix blocking (std::thread) and async (tokio) code freely without any special consideration.
Part 2: Cargo features and workspaces
Knowledge check
- 1.A library has
default = ["json"]in its [features]. A dependent crate addsmy-lib = { version = "1", default-features = false }. Which features are active? - 2.Two workspace members both depend on
serde = "1". With a shared workspace Cargo.lock, how many times is serde compiled?
Part 3: Testing strategy
Knowledge check
- 1.You have a public function with complex logic and several edge cases. What is the most effective testing approach?
- 2.A doc test that uses
?inside an example block will fail to compile because main() does not return Result. - 3.Tests that share global mutable state fail intermittently when run in parallel. The simplest fix is:
Part 4: Macro patterns
Knowledge check
- 1.In
macro_rules!, what does$($x:expr),+match? - 2.You want to auto-implement a Display trait for 10 newtype structs with identical formatting. The best approach is:
Putting it together
The advanced topics are connected: async and threads both rely on the ownership and Send/Sync foundations from the intermediate track. Cargo features and workspaces organise the codebase so tests, benchmarks, and optional features stay cleanly separated. Macros reduce the boilerplate that would otherwise make those patterns tedious to maintain.
Revisit any lesson that surfaced uncertainty. The best way to consolidate this knowledge is a real project that uses several of these features together — a CLI tool, a small HTTP service, or a library with a clean public API and thorough test coverage.
Where to go next
Congratulations — you've covered the full Rust track, from ownership basics through async concurrency, ecosystem tooling, and metaprogramming. The natural next steps:
- Build something real: the Rust Book's project chapters are excellent.
- Read the
stddocumentation — the standard library is full of traits and patterns you'll recognise now. - Explore the ecosystem:
serde(serialization),tokio(async),axumoractix-web(HTTP),sqlx(async SQL). - The Fundamentals track covers systems concepts (memory, processes, networking) that Rust makes directly accessible.