File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -276,6 +276,25 @@ Mutable references will set the mode to `ref mut` unless the mode is already `re
276
276
which case it remains ` ref ` . If the automatically dereferenced value is still a reference,
277
277
it is dereferenced and this process repeats.
278
278
279
+ Move bindings and reference bindings can be mixed together in the same pattern, doing so will
280
+ result in partial move of the object bound to and the object cannot be used afterwards.
281
+ This applies only if the type cannot be copied.
282
+
283
+ In the example below, ` name ` is moved out of ` person ` , trying to use ` person ` as a whole or
284
+ ` person.name ` would result in an error because of * partial move* .
285
+
286
+ Example:
287
+
288
+ ``` rust
289
+ # struct Person {
290
+ # name : String ,
291
+ # age : u8 ,
292
+ # }
293
+ # let person = Person { name : String :: from (" John" ), age : 23 };
294
+ // `name` is moved from person and `age` referenced
295
+ let Person { name , ref age } = person ;
296
+ ```
297
+
279
298
## Wildcard pattern
280
299
281
300
> ** <sup >Syntax</sup >** \
You can’t perform that action at this time.
0 commit comments