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