@@ -29,8 +29,10 @@ struct Point {
2929// Structs can be reused as fields of another struct
3030#[allow(dead_code)]
3131struct Rectangle {
32- p1: Point,
33- p2: Point,
32+ // A rectangle can be specified by where the top left and bottom right
33+ // corners are in space.
34+ top_left: Point,
35+ bottom_right: Point,
3436}
3537
3638fn main() {
@@ -44,23 +46,26 @@ fn main() {
4446
4547
4648 // Instantiate a `Point`
47- let point: Point = Point { x: 0 .3, y: 0.4 };
49+ let point: Point = Point { x: 10 .3, y: 0.4 };
4850
4951 // Access the fields of the point
5052 println!("point coordinates: ({}, {})", point.x, point.y);
5153
52- // Make a new point by using struct update syntax to use the fields of our other one
53- let new_point = Point { x: 0.1, ..point };
54- // `new_point.y` will be the same as `point.y` because we used that field from `point`
55- println!("second point: ({}, {})", new_point.x, new_point.y);
54+ // Make a new point by using struct update syntax to use the fields of our
55+ // other one
56+ let bottom_right = Point { x: 5.2, ..point };
57+
58+ // `bottom_right.y` will be the same as `point.y` because we used that field
59+ // from `point`
60+ println!("second point: ({}, {})", bottom_right.x, bottom_right.y);
5661
5762 // Destructure the point using a `let` binding
58- let Point { x: my_x , y: my_y } = point;
63+ let Point { x: top_edge , y: left_edge } = point;
5964
6065 let _rectangle = Rectangle {
6166 // struct instantiation is an expression too
62- p1 : Point { x: my_y , y: my_x },
63- p2: point ,
67+ top_left : Point { x: left_edge , y: top_edge },
68+ bottom_right: bottom_right ,
6469 };
6570
6671 // Instantiate a unit struct
0 commit comments