Lộ trình học

Struct, enum và trait

Mô hình hóa dữ liệu bằng struct và enum, so khớp mẫu, xử lý Option và Result, chia sẻ hành vi bằng trait và generics.

10 bài học · 14 thử thách

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