From 0856d0c08089bdb22ba4aa1e43d5ec59104b296d Mon Sep 17 00:00:00 2001 From: laurens Date: Fri, 22 May 2020 14:08:20 +0200 Subject: [PATCH] rectangles: add can_hold function --- rectangles/src/main.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rectangles/src/main.rs b/rectangles/src/main.rs index a1cae3e..7fbbbd0 100644 --- a/rectangles/src/main.rs +++ b/rectangles/src/main.rs @@ -8,6 +8,10 @@ impl Rectangle { fn area(&self) -> u32 { self.width * self.height } + + fn can_hold(&self, other: &Rectangle) -> bool { + self.width > other.width && self.height > other.height + } } fn main() { @@ -40,6 +44,12 @@ fn main() { "The area of the rectangle is {} square pixels.", rect.area() ); + + println!( + "The rectangle {:#?} can hold itself obviously: {}.", + rect, + rect.can_hold(&rect), + ); } fn area(width: u32, height: u32) -> u32 {