File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -733,22 +733,22 @@ fn point_from_direction(dir: Direction) -> Point {
733733}
734734~~~~
735735
736- A special kind of enum variant, called _ struct-like enums_ ,
737- can have its fields extracted with dot notation and not just destructuring.
738- For example:
736+ Enum variants may also be structs. For example:
739737
740738~~~~
741739# use core::float;
742740# struct Point {x: float, y: float}
743741# fn square(x: float) -> float { x * x }
744742enum Shape {
745743 Circle { center: Point, radius: float },
746- Rectangle { left : Point, right : Point }
744+ Rectangle { top_left : Point, bottom_right : Point }
747745}
748746fn area(sh: Shape) -> float {
749747 match sh {
750- Circle(c) => float::consts::pi * square(c.radius),
751- Rectangle(r) => r.right.x - r.left.x * r.right.y - r.right.y
748+ Circle { radius: radius, _ } => float::consts::pi * square(radius),
749+ Rectangle { top_left: top_left, bottom_right: bottom_right } => {
750+ (bottom_right.x - top_left.x) * (bottom_right.y - top_left.y)
751+ }
752752 }
753753}
754754~~~~
You can’t perform that action at this time.
0 commit comments