File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -13,12 +13,12 @@ fn main() {
13
13
#[derive(Debug)]
14
14
struct Person {
15
15
name: String,
16
- age: u8 ,
16
+ age: Box<u8> ,
17
17
}
18
18
19
19
let person = Person {
20
20
name: String::from("Alice"),
21
- age: 20 ,
21
+ age: Box::new(20) ,
22
22
};
23
23
24
24
// `name` is moved out of person, but `age` is referenced
@@ -35,6 +35,13 @@ fn main() {
35
35
println!("The person's age from person struct is {}", person.age);
36
36
}
37
37
```
38
+ (In this example, we store the ` age ` variable on the heap to
39
+ illustrate the partial move: deleting ` ref ` in the above code would
40
+ give an error as the ownership of ` person.age ` would be moved to the
41
+ variable ` age ` . If ` Person.age ` were stored on the stack, ` ref ` would
42
+ not be required as the definition of ` age ` would copy the data from
43
+ ` person.age ` without moving it.)
44
+
38
45
### See also:
39
46
[ destructuring] [ destructuring ]
40
47
You can’t perform that action at this time.
0 commit comments