From 140be9b1b4f294805c9356da45a13a6ff806e99d Mon Sep 17 00:00:00 2001 From: Phillip Date: Mon, 7 Sep 2026 17:56:40 +0200 Subject: [PATCH 1/3] Allow equal-sized rectangles in can_hold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since equal-sized rectangles can fit exactly, shouldn’t can_hold use >= instead of >? If > is intentional, the book should clarify that it requires extra space. --- .../listing-05-15/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-15/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/listing-05-15/src/main.rs index e6a32723f1..9732bb3bed 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-15/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-15/src/main.rs @@ -11,7 +11,7 @@ impl Rectangle { } fn can_hold(&self, other: &Rectangle) -> bool { - self.width > other.width && self.height > other.height + self.width >= other.width && self.height >= other.height } } // ANCHOR_END: here From 34cc1d65e4e2282e7defa77c9fd97b0d5f9b347e Mon Sep 17 00:00:00 2001 From: Phillip Date: Mon, 7 Sep 2026 18:15:04 +0200 Subject: [PATCH 2/3] Fix can_hold example in listing 5-16 --- .../listing-05-16/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs index a5d3f772a8..e03b10ca7b 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs @@ -4,6 +4,7 @@ struct Rectangle { height: u32, } + // ANCHOR: here impl Rectangle { fn area(&self) -> u32 { @@ -11,13 +12,15 @@ impl Rectangle { } } + impl Rectangle { fn can_hold(&self, other: &Rectangle) -> bool { - self.width > other.width && self.height > other.height + self.width >= other.width && self.height >= other.height } } // ANCHOR_END: here + fn main() { let rect1 = Rectangle { width: 30, @@ -32,6 +35,7 @@ fn main() { height: 45, }; + println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2)); println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3)); } From 1ba8bc3d7dd74519ef07957bda4d221c740c59bb Mon Sep 17 00:00:00 2001 From: Phillip Date: Mon, 7 Sep 2026 18:17:57 +0200 Subject: [PATCH 3/3] Normalize whitespace in listing 5-16 --- .../listing-05-16/src/main.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs b/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs index e03b10ca7b..3006040213 100644 --- a/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs +++ b/listings/ch05-using-structs-to-structure-related-data/listing-05-16/src/main.rs @@ -4,7 +4,6 @@ struct Rectangle { height: u32, } - // ANCHOR: here impl Rectangle { fn area(&self) -> u32 { @@ -12,7 +11,6 @@ impl Rectangle { } } - impl Rectangle { fn can_hold(&self, other: &Rectangle) -> bool { self.width >= other.width && self.height >= other.height @@ -20,7 +18,6 @@ impl Rectangle { } // ANCHOR_END: here - fn main() { let rect1 = Rectangle { width: 30, @@ -35,7 +32,6 @@ fn main() { height: 45, }; - println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2)); println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3)); }