Skip to content

Commit

Permalink
Merge pull request #881 from Amjad50/move_ref_pattern
Browse files Browse the repository at this point in the history
Add `move_ref_pattern` docs
  • Loading branch information
ehuss committed Oct 17, 2020
2 parents 1b78182 + 840993a commit e526381
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,25 @@ Mutable references will set the mode to `ref mut` unless the mode is already `re
which case it remains `ref`. If the automatically dereferenced value is still a reference,
it is dereferenced and this process repeats.

Move bindings and reference bindings can be mixed together in the same pattern, doing so will
result in partial move of the object bound to and the object cannot be used afterwards.
This applies only if the type cannot be copied.

In the example below, `name` is moved out of `person`, trying to use `person` as a whole or
`person.name` would result in an error because of *partial move*.

Example:

```rust
# struct Person {
# name: String,
# age: u8,
# }
# let person = Person{ name: String::from("John"), age: 23 };
// `name` is moved from person and `age` referenced
let Person { name, ref age } = person;
```

## Wildcard pattern

> **<sup>Syntax</sup>**\
Expand Down

0 comments on commit e526381

Please sign in to comment.