From e011a4f94fa766135ec761b3b79fd636cb205f78 Mon Sep 17 00:00:00 2001 From: laurens Date: Fri, 22 May 2020 14:06:55 +0200 Subject: [PATCH] rectangles: implement area method --- rectangles/src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 {