Created
March 14, 2023 15:24
-
-
Save computermouth/ee624db58383b4881dfe46f0631d4544 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Point { | |
x: isize, | |
y: isize, | |
} | |
struct Circle { | |
center: Point, | |
radius: f64, | |
} | |
enum Shape { | |
Circle(Circle), | |
Triangle([Point; 3]), | |
Square([Point; 4]), | |
} | |
fn draw_circle(c: Circle) { | |
_ = c.center; | |
_ = c.radius; | |
todo!(); | |
} | |
fn draw_polygon(p: &[Point]) { | |
_ = p[0].x; | |
_ = p[0].y; | |
todo!(); | |
} | |
fn draw(s: Shape) { | |
match s { | |
Shape::Circle(c) => draw_circle(c), | |
Shape::Triangle(points) => draw_polygon(&points), | |
Shape::Square(points) => draw_polygon(&points), | |
} | |
} | |
fn main() { | |
let circ = Shape::Circle ( | |
Circle { | |
center: Point { x: 0, y: 0 }, | |
radius: 1.0, | |
} | |
); | |
let tri = Shape::Triangle ( | |
[ | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
] | |
); | |
let sq = Shape::Square ( | |
[ | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
Point { x: 0, y: 0 }, | |
] | |
); | |
draw(circ); | |
draw(tri); | |
draw(sq); | |
println!("Hello, world!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment