Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listing 5-6: Creating a new User instance using all but one of the values from user1 #3488

Closed
telbizov opened this issue Dec 30, 2022 · 1 comment · Fixed by #3878
Closed

Comments

@telbizov
Copy link

URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch05-01-defining-structs.html

Description of the problem:
Listing 5-6 code reads:

fn main() {
    // --snip--

    let user2 = User {
        active: user1.active,
        username: user1.username,
        email: String::from("another@example.com"),
        sign_in_count: user1.sign_in_count,
    };
}

Listing 5-6: Creating a new User instance using one of the values from user1

It seems to me that we we are copying all the fields from user1 into user2 and only changing one of them - email.

Suggested fix:

Maybe the description under the code should say:

Listing 5-6: Creating a new User instance using all but one of the values from user1

chriskrycho added a commit that referenced this issue Apr 5, 2024
It used to have the inverse of what it was actually doing!

Fixes #3488
@chriskrycho
Copy link
Contributor

Thanks for filing this – you’re absolutely right! I just opened #3878 to fix this. Much obliged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants