@@ -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 and enum values that match all criteria defined by its subpatterns.
601
- They are also used to [ destructure] ( #destructuring ) a struct or enum value.
600
+ Struct patterns match struct, enum, and union values that match all criteria defined by its subpatterns.
601
+ They are also used to [ destructure] ( #destructuring ) a struct, enum, or union 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
@@ -642,7 +642,7 @@ match m {
642
642
}
643
643
```
644
644
645
- If ` .. ` is not used, it is required to match all fields:
645
+ If ` .. ` is not used, a struct pattern used to match a struct is required to specify all fields:
646
646
647
647
``` rust
648
648
# struct Struct {
@@ -661,6 +661,8 @@ match struct_value {
661
661
}
662
662
```
663
663
664
+ A struct pattern used to match a union must specify exactly one field (see [ Pattern matching on unions] ).
665
+
664
666
The ` ref ` and/or ` mut ` _ IDENTIFIER_ syntax matches any value and binds it to a variable with the same name as the given field.
665
667
666
668
``` rust
@@ -867,6 +869,7 @@ For example, `x @ A(..) | B(..)` will result in an error that `x` is not bound i
867
869
[ literal expression ] : expressions/literal-expr.md
868
870
[ negating ] : expressions/operator-expr.md#negation-operators
869
871
[ path ] : expressions/path-expr.md
872
+ [ pattern matching on unions ] : items/unions.md#pattern-matching-on-unions
870
873
[ range expressions ] : expressions/range-expr.md
871
874
[ structs ] : items/structs.md
872
875
[ tuples ] : types/tuple.md
0 commit comments