Skip to content

Commit 752eab0

Browse files
authored
Merge pull request #2054 from ehuss/clarify-binding-shorthand
Clarify struct pattern binding shorthand
2 parents 1d930e1 + c483f00 commit 752eab0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/patterns.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ r[patterns.struct.constraint-union]
810810
A struct pattern used to match a union must specify exactly one field (see [Pattern matching on unions]).
811811

812812
r[patterns.struct.binding-shorthand]
813-
The `ref` and/or `mut` [IDENTIFIER] syntax matches any value and binds it to a variable with the same name as the given field.
813+
The [IDENTIFIER] syntax matches any value and binds it to a variable with the same name as the given field. It is a shorthand for `fieldname: fieldname`. The `ref` and `mut` qualifiers can be included with the behavior as described in [patterns.ident.ref].
814814

815815
```rust
816816
# struct Struct {
@@ -820,7 +820,7 @@ The `ref` and/or `mut` [IDENTIFIER] syntax matches any value and binds it to a v
820820
# }
821821
# let struct_value = Struct{a: 10, b: 'X', c: false};
822822
#
823-
let Struct{a: x, b: y, c: z} = struct_value; // destructure all fields
823+
let Struct { a, b, c } = struct_value;
824824
```
825825

826826
r[patterns.struct.refutable]

0 commit comments

Comments
 (0)