rectangles: add can_hold function
This commit is contained in:
parent
e011a4f94f
commit
0856d0c080
1 changed files with 10 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue