Closed
Description
URL to the section(s) of the book with this problem:
book/src/ch05-01-defining-structs.md
Line 134 in 8a0bb3c
Description of the problem:
The following text isn't accurate
In this example, we can no longer use user1 after creating user2 because the String in the username field of user1 was moved into user2
You can still use all of user1, except the username property. For example this code works:
struct User {
active: bool,
username: String,
email: String,
sign_in_count: u64,
}
fn main() {
let user1 = User {
email: String::from("[email protected]"),
username: String::from("someusername123"),
active: true,
sign_in_count: 1,
};
let user2 = User {
email: String::from("[email protected]"),
..user1
};
println!("{}", user1.email);
println!("{}", user2.email);
}
Suggested fix:
In this example, we can no longer use the username property of user1 after creating user2 because the String in the username field of user1 was moved into user2
Metadata
Metadata
Assignees
Labels
No labels