Skip to content
← All Rust tracks

Shape Your Data: Structs, Enums, Pattern Matching

Rust

Represent 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.

24 exercises

2 articles

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Not solved yet. Structs: naming your data Practice · Easy
  2. 2 Not solved yet. Field init shorthand and struct update syntax Practice · Easy
  3. 3 Not solved yet. Convert distances with tuple and unit structs Practice · Easy
  4. 4 Not solved yet. impl blocks: associated functions, methods, Self and associated constants Practice · Easy
  5. 5 Not solved yet. Replace a manual default with a derive Practice · Easy
  6. 6 Not solved yet. Represent commands with enum variants Practice · Easy
  7. 7 Not solved yet. match and exhaustiveness: the compiler as a checklist Practice · Easy
  8. 8 Not solved yet. The wildcard trap: _ arms freeze your enum against the future Practice · Medium
  9. 9 Not solved yet. Literal, range and or-patterns Practice · Easy
  10. 10 Not solved yet. Binding values with @ and or-patterns Practice · Medium
  11. 11 Not solved yet. Destructuring structs and nested patterns Practice · Medium
  12. 12 Not solved yet. Slice and array patterns, and rest @ .. Practice · Medium
  13. 13 Not solved yet. Grade scores with match guards Practice · Medium
  14. 14 Not solved yet. Refutability, and every place a pattern can appear Practice · Medium
  15. 15 Not solved yet. Simplify stack control flow with pattern matching Practice · Easy
  16. 16 Not solved yet. Combine pattern matches with let-chains Practice · Medium
  17. 17 Not solved yet. Count enum variants with matches! Practice · Easy
  18. 18 Not solved yet. #[derive(Debug)] and the three shapes of debug output Practice · Easy
  19. 19 Not solved yet. Compare weighted records without requiring Eq Practice · Medium
  20. 20 Not solved yet. Derive consistent ordering for versions and priorities Practice · Medium
  21. 21 Not solved yet. Make hashing agree with equality Practice · Medium
  22. 22 Not solved yet. Build a configuration from defaults and overrides Practice · Easy
  23. 23 Not solved yet. Decode bytes into enum variants Practice · Medium
  24. 24 #[non_exhaustive]: designing enums you can extend later Read
  25. 25 Not solved yet. Protect rectangle invariants with private fields Practice · Easy
  26. 26 Choose what belongs in a struct or enum Read

Check yourself

4 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 4 correct

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>>());
}
Question 1 of 4