You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/patterns.md
+15-3Lines changed: 15 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -597,8 +597,8 @@ Reference patterns are always irrefutable.
597
597
[_OuterAttribute_]: attributes.md
598
598
[TUPLE_INDEX]: tokens.md#tuple-index
599
599
600
-
Struct patterns match struct values that match all criteria defined by its subpatterns.
601
-
They are also used to [destructure](#destructuring) a struct.
600
+
Struct patterns match struct and enum values that match all criteria defined by its subpatterns.
601
+
They are also used to [destructure](#destructuring) a struct or enum value.
602
602
603
603
On a struct pattern, the fields are referenced by name, index (in the case of tuple structs) or ignored by use of `..`:
604
604
@@ -628,6 +628,18 @@ match t {
628
628
PointTuple {0:10, ..} => (),
629
629
PointTuple {..} => (),
630
630
}
631
+
632
+
# enumMessage {
633
+
# Quit,
634
+
# Move { x:i32, y:i32 },
635
+
# }
636
+
# letm=Message::Quit;
637
+
#
638
+
matchm {
639
+
Message::Quit=> (),
640
+
Message::Move {x:10, y:20} => (),
641
+
Message::Move {..} => (),
642
+
}
631
643
```
632
644
633
645
If `..` is not used, it is required to match all fields:
@@ -662,7 +674,7 @@ The `ref` and/or `mut` _IDENTIFIER_ syntax matches any value and binds it to a v
662
674
letStruct{a:x, b:y, c:z} =struct_value; // destructure all fields
663
675
```
664
676
665
-
A struct pattern is refutable when one of its subpatterns is refutable.
677
+
A struct pattern is refutable if the _PathInExpression_ resolves to a constructor of an enum with more than one variant, or one of its subpatterns is refutable.
0 commit comments