Slide 29
Slide 29 text
enum
1 enum Shape {
2 Rect (i32, i32, u32, u32), // (x, y, width, height)
3 Circle {x: i32, y: i32, r: u32},
4 Empty,
5 }
6
7 fn print_shape(shape: Shape) {
8 match shape {
9 Shape::Rect (x, y, w, h) => println!("Rect {} {} {} {}", x, y, w, h),
10 Shape::Circle {x, y, r} => println!("Circle {} {} {}", x, y, r),
11 _ => println!("Other"),
12 }
13 }
14
15 fn main() {
16 print_shape(Shape::Rect (10, -20, 50, 50));
17 print_shape(Shape::Circle {x: -10, y: 0, r: 5});
18 print_shape(Shape::Empty);
19 }