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

3.1 Structures "because we used that field from point" should be "another_point" #1846

Open
Basiliotornado opened this issue May 16, 2024 · 1 comment

Comments

@Basiliotornado
Copy link

At least, I'm pretty sure.
Line for reference:

    // Instantiate a `Point`
    let point: Point = Point { x: 10.3, y: 0.4 };
    let another_point: Point = Point { x: 5.2, y: 0.2 };

    // Access the fields of the point
    println!("point coordinates: ({}, {})", point.x, point.y);

    // Make a new point by using struct update syntax to use the fields of our
    // other one
    let bottom_right = Point { x: 5.2, ..another_point };

    // `bottom_right.y` will be the same as `point.y` because we used that field
    // from `point`
    println!("second point: ({}, {})", bottom_right.x, bottom_right.y);

Which prints

point coordinates: (10.3, 0.4)
second point: (5.2, 0.2)

As you can see, it is the same as another_point.y, and not point.y :)

@daniel-pg
Copy link

I was about to report the same issue 😅
The comment should be changed to:

// `bottom_right.y` will be the same as `another_point.y` because we used that field

We could also change the code, but then the println! wouldn't make sense because it was supposed to print the values of the "second" point (although a third is created).

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

No branches or pull requests

2 participants