diff options
| author | mo khan <mo@mokhan.ca> | 2025-06-03 16:06:08 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-06-03 16:06:08 -0600 |
| commit | 7e23900159e3ba26c178a3a22c21d264517abeb7 (patch) | |
| tree | 2dd95299aa78664f95296c32c4ea570e2d552710 | |
| parent | 456eb97609267215e31215ab91277808ab54127a (diff) | |
| -rw-r--r-- | 5.3/src/main.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/5.3/src/main.rs b/5.3/src/main.rs index 9d12566..5e7a7e6 100644 --- a/5.3/src/main.rs +++ b/5.3/src/main.rs @@ -12,6 +12,13 @@ impl Rectangle { fn can_hold(&self, other: &Rectangle) -> bool { self.width > other.width && self.height > other.height } + + fn square(size: u32) -> Self { + Self { + width: size, + height: size, + } + } } fn main() { @@ -27,6 +34,7 @@ fn main() { width: 60, height: 45, }; + let rect4 = Rectangle::square(10); println!( "The area of the rectangle is {} square pixels.", @@ -34,4 +42,5 @@ fn main() { ); println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2)); println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3)); + println!("rect4 is a square: {}", &rect4.area()); } |
