hd-lang

Tour · 5 of 25

A match covers every case, so a new case can't be forgotten

An enum is a closed list of cases, and a case can carry data, such as the carrier of a shipped order. match picks the case and unpacks its data, and it must cover every case. When the business adds refunds, the compiler lists every match that does not handle them yet, before a customer finds the gap. A catch-all _ => arm would silence that list, so keep it for when "everything else" really has one answer. Comparing two statuses with == is a separate matter: an enum can be compared only if it asks with @derive(Eq). Without that line, status == OrderStatus.Pending is rejected. match needs no derive.

Run: Ctrl+Enter · Pages: Alt+← Alt+→