Skip to content

Instantly share code, notes, and snippets.

@computermouth
Created March 14, 2023 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save computermouth/ee624db58383b4881dfe46f0631d4544 to your computer and use it in GitHub Desktop.
Save computermouth/ee624db58383b4881dfe46f0631d4544 to your computer and use it in GitHub Desktop.
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