Lernpfad

Structs, Enums und Traits

Daten mit Structs und Enums modellieren, Muster abgleichen, Option und Result behandeln, Verhalten mit Traits und Generics teilen.

10 Lektionen · 14 Challenges

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