Skip to content

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

@telbizov

Description

@telbizov

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions