-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.rs
32 lines (26 loc) · 796 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Implement a trait called Drawable with a method draw and implement it for different shapes (Circle, Square, Rectangle).
trait Drawable {
fn draw(&self);
}
enum Shapes {
Circle(f32),
Square(u32),
Rectangle(u32, u32)
}
impl Drawable for Shapes {
fn draw(&self) {
match self {
Self::Circle(r) => println!("Draw a circle of radius {}.", r),
Self::Square(s) => println!("Draw a square of side {}.", s),
Self::Rectangle(l, b) => println!("Draw a rectangle of length {} and bredth {}.", l, b),
}
}
}
fn main() {
let circle: Shapes = Shapes::Circle(42.5);
circle.draw();
let square: Shapes = Shapes::Square(8);
square.draw();
let rectangle: Shapes = Shapes::Rectangle(7, 4);
rectangle.draw();
}