diff --git a/rectangles/src/main.rs b/rectangles/src/main.rs index 273fa5d..87422bd 100644 --- a/rectangles/src/main.rs +++ b/rectangles/src/main.rs @@ -13,6 +13,15 @@ impl Rectangle { } } +impl Rectangle { + fn square(size: u32) -> Self { + Self { + width: size, + height: size, + } + } +} + @@ -29,5 +38,9 @@ fn main() { println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2)); println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3)); + + let sq = Rectangle::square(5); + println!("r: {:?}", sq); + }