Skip to content

Commit

Permalink
Add struct pattern to doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Sep 28, 2022
1 parent 2ef3b81 commit 80fc0ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docs/src/spec/statements/match.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@
> &nbsp;&nbsp; _PatternElem_ ( `|` _PatternElem_ )<sup>*</sup>\
>
> _PatternElem_ : \
> &nbsp;&nbsp; [_IDENTIFIER_] | [_BOOLEAN_LITERAL_] | `_` | `..` | [_Path_] | [_Path_]`(` _TuplePatterns_<sup>?</sup> `)` | `(` _TuplePatterns_<sup>?</sup> `)`\
> &nbsp;&nbsp; [_IDENTIFIER_] | [_BOOLEAN_LITERAL_] | `_` | `..` | [_Path_] \|\
> &nbsp;&nbsp; [_Path_]`(` _TuplePatterns_<sup>?</sup> `)` |`(` _TuplePatterns_<sup>?</sup> `)` \|\
> &nbsp;&nbsp; [_Path_]`{` _StructPatterns_<sup>?</sup> `}`\
>
> _TuplePatterns_ :\
> &nbsp;&nbsp; _Pattern_ ( `,` _Pattern_ )<sup>\*</sup>
> _TuplePatterns_ : \
> &nbsp;&nbsp; _Pattern_ ( `,` _Pattern_ )<sup>\*</sup>\
>
> _StructPatterns_ : \
> &nbsp;&nbsp; _Field_ ( `,` _Field_)<sup>\*</sup>(`,` `..`)<sup>?</sup>\
>
> _Field_ : \
> &nbsp;&nbsp; [_IDENTIFIER_] `:` _Pattern_\

A `match` statements compares `expression` with patterns, then executes body of the matched arm.
Expand Down
1 change: 1 addition & 0 deletions newsfragments/770.feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ For now, available patterns are restricted to
* Boolean literal(`true` and `false`)
* Enum variant. e.g., `MyEnum::Tuple(a, b, c)`
* Tuple pattern. e.g., `(a, b, c)`
* Struct pattern. e.g., `MyStruct {x: x1, y: y1, b: true}`
* Rest pattern(`..`), which matches the rest of the pattern. e.g., `MyEnum::Tuple(.., true)`
* Or pattern(|). e.g., MyEnum::Unit | MyEnum::Tuple(.., true)

Expand Down

0 comments on commit 80fc0ac

Please sign in to comment.