We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Shape Your Data: Structs, Enums, Pattern Matching
RustRepresent data with structs and enums, handle cases with pattern matching, and use newtypes and builders to express constraints.
This track uses Rust. You can make it your practice mode to browse related content across the site.
Your learning sequence
- 1 Not solved yet. Structs: naming your data Practice · Easy
- 2 Not solved yet. Field init shorthand and struct update syntax Practice · Easy
- 3 Not solved yet. Convert distances with tuple and unit structs Practice · Easy
- 4 Not solved yet. impl blocks: associated functions, methods, Self and associated constants Practice · Easy
- 5 Not solved yet. Replace a manual default with a derive Practice · Easy
- 6 Not solved yet. Represent commands with enum variants Practice · Easy
- 7 Not solved yet. match and exhaustiveness: the compiler as a checklist Practice · Easy
-
8
Not solved yet.
The wildcard trap:
_arms freeze your enum against the future Practice · Medium - 9 Not solved yet. Literal, range and or-patterns Practice · Easy
- 10 Not solved yet. Binding values with @ and or-patterns Practice · Medium
- 11 Not solved yet. Destructuring structs and nested patterns Practice · Medium
- 12 Not solved yet. Slice and array patterns, and rest @ .. Practice · Medium
- 13 Not solved yet. Grade scores with match guards Practice · Medium
- 14 Not solved yet. Refutability, and every place a pattern can appear Practice · Medium
- 15 Not solved yet. Simplify stack control flow with pattern matching Practice · Easy
- 16 Not solved yet. Combine pattern matches with let-chains Practice · Medium
- 17 Not solved yet. Count enum variants with matches! Practice · Easy
- 18 Not solved yet. #[derive(Debug)] and the three shapes of debug output Practice · Easy
- 19 Not solved yet. Compare weighted records without requiring Eq Practice · Medium
- 20 Not solved yet. Derive consistent ordering for versions and priorities Practice · Medium
- 21 Not solved yet. Make hashing agree with equality Practice · Medium
- 22 Not solved yet. Build a configuration from defaults and overrides Practice · Easy
- 23 Not solved yet. Decode bytes into enum variants Practice · Medium
- 24 #[non_exhaustive]: designing enums you can extend later Read
- 25 Not solved yet. Protect rectangle invariants with private fields Practice · Easy
- 26 Choose what belongs in a struct or enum Read
Check yourself
4 questions · not saved while you're signed outUse these questions to check your understanding and compare explanations. Your score does not affect track completion.
Why can Option<Box<u8>> match the box size while Option<u8> needs more space than u8?
Choose one answer to reveal the explanations. Answers are kept only while this page is open.
use std::mem::size_of;
fn main() {
println!("Option<Box<u8>>: {}", size_of::<Option<Box<u8>>>());
println!("Box<u8>: {}", size_of::<Box<u8>>());
println!("Option<u8>: {}", size_of::<Option<u8>>());
}