Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

บทที่ 7: Enums & Pattern Matching

Enums ช่วยให้เราแสดงค่าที่เป็นไปได้หลายแบบ และ Pattern Matching ช่วยจัดการแต่ละแบบ


สิ่งที่จะได้เรียนรู้

หัวข้อคำอธิบาย
การสร้าง Enumนิยาม variants
Option<T>จัดการค่าที่อาจไม่มี
MatchPattern matching
if letConcise matching

Enums คืออะไร?

Enum แสดงว่าค่าเป็น หนึ่งใน หลายตัวเลือก:

#![allow(unused)]
fn main() {
enum Direction {
    North,
    South,
    East,
    West,
}
}

ค่าของ Direction ต้องเป็น North, South, East, หรือ West เท่านั้น


เริ่มกันเลย!

👉 การสร้าง Enum