Chapter 23

Rust Fundamentals Quiz

👋 Anyone can read and edit this exercise. Sign up to save your progress.

If you can answer these without flipping back, you've internalised more Rust than you think.

Twenty multiple-choice questions covering the ground we've walked together: ownership and borrowing, Option and Result, lifetimes, traits, enums, modules. Pick an answer to lock it in and reveal the explanations — not just for the right answer, but for every distractor too, because the wrong answers are usually where the learning lives.

No grade, no time limit, no record kept. Skim the explanations even for the ones you got right — sometimes the why is more interesting than the what.

0 / 20 answered
  1. Question 1of 20

    What happens when you pass a String to a function in Rust?

    Think about ownership rules.

  2. Question 2of 20

    Which of these creates a mutable variable in Rust?

  3. Question 3of 20

    What is Option<T> for?

    Think about what other languages reach for null to express.

  4. Question 4of 20

    How do you borrow a value immutably?

  5. Question 5of 20

    Which statement about Rust's ownership is correct?

  6. Question 6of 20

    What's the difference between String and &str?

  7. Question 7of 20

    What does #[derive(Debug)] do?

  8. Question 8of 20

    What does the ? operator do on a Result<T, E>?

    It collapses a very common match pattern.

  9. Question 9of 20

    Which of these creates an empty Vec?

  10. Question 10of 20

    What happens if you call HashMap::get for a key that doesn't exist?

    Rust prefers types over panics for expected absence.

  11. Question 11of 20

    How do you create an owned String from a string literal?

  12. Question 12of 20

    Which of these is true of Rust enums?

    Rust enums are closer to algebraic data types than to C-style enums.

  13. Question 13of 20

    What does the lifetime in this signature say?

    fn longest<'a>(x: &'a str, y: &'a str) -> &'a str
    

    'a is the shorter of x's and y's lifetimes.

  14. Question 14of 20

    What does .clone() typically do?

  15. Question 15of 20

    What is match primarily for?

  16. Question 16of 20

    When is a value's drop method called?

    Same answer that explains why Rust doesn't need a garbage collector.

  17. Question 17of 20

    What does the 'static lifetime mean?

  18. Question 18of 20

    What is a trait in Rust?

  19. Question 19of 20

    How do you make an item visible from outside its module?

  20. Question 20of 20

    Which of these does not create a reference?

    * is the dereference operator.

Next chapter 24Appendix