diff --git a/rectangles/src/main.rs b/rectangles/src/main.rs index 9a1568c..a1cae3e 100644 --- a/rectangles/src/main.rs +++ b/rectangles/src/main.rs @@ -4,6 +4,12 @@ struct Rectangle { height: u32, } +impl Rectangle { + fn area(&self) -> u32 { + self.width * self.height + } +} + fn main() { let width1 = 30; let height1 = 50; @@ -29,6 +35,11 @@ fn main() { "The area of the rectangle is {} square pixels.", area_struct(&rect) ); + + println!( + "The area of the rectangle is {} square pixels.", + rect.area() + ); } fn area(width: u32, height: u32) -> u32 {