Parcours d'apprentissage

Structs, enums et traits

Modélisez vos données avec des structs et des enums, filtrez par motifs, gérez Option et Result, partagez du comportement avec les traits et les génériques.

10 leçons · 14 défis

  1. Leçon 1 défi Structs Group related values into your own type with named fields.
  2. Leçon 2 défis Methods and impl Blocks Attach functions to a struct with impl, including constructors.
  3. Leçon 1 défi Enums Define a type that is one of several variants, each with its own data.
  4. Leçon 2 défis Pattern Matching with match Compare a value against patterns with match, guards and if let.
  5. Leçon 1 défi Temperature Converter Convert between Celsius and Fahrenheit with an enum.
  6. Leçon 2 défis Option: Values That May Be Missing Represent a missing value with Option instead of null.
  7. Leçon 2 défis Error Handling with Result Return errors as values with Result and pass them on with the ? operator.
  8. Leçon 1 défi Bank Account with Result Model deposits and withdrawals that can fail with your own error type.
  9. Leçon 1 défi Traits Describe shared behavior with a trait and implement it for different types.
  10. Leçon 1 défi Generics Write one function or struct that works with many types.