Lộ trình học Rust

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.

Chạy thử Rust online

8 bài học

Structs

Group related values into your own type with named fields.

Xem bài học →

Enums

Define a type that is one of several variants, each with its own data.

Xem bài học →

Traits

Describe shared behavior with a trait and implement it for different types.

Xem bài học →

Generics

Write one function or struct that works with many types.

Xem bài học →