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() {
1313 #[derive(Debug)]
1414 struct Person {
1515 name: String,
16- age: u8 ,
16+ age: Box<u8> ,
1717 }
1818
1919 let person = Person {
2020 name: String::from("Alice"),
21- age: 20 ,
21+ age: Box::new(20) ,
2222 };
2323
2424 // `name` is moved out of person, but `age` is referenced
@@ -35,6 +35,13 @@ fn main() {
3535 println!("The person's age from person struct is {}", person.age);
3636}
3737```
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+
3845### See also:
3946[ destructuring] [ destructuring ]
4047
You can’t perform that action at this time.
0 commit comments