Rect area as method
This commit is contained in:
parent
3211792108
commit
154344fc1d
@ -4,6 +4,12 @@ struct Rectangle {
|
|||||||
height: u32,
|
height: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Rectangle {
|
||||||
|
fn area(&self) -> u32 {
|
||||||
|
self.width * self.height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rect1 = Rectangle { width: 30, height: 50 };
|
let rect1 = Rectangle { width: 30, height: 50 };
|
||||||
|
|
||||||
@ -11,10 +17,6 @@ fn main() {
|
|||||||
|
|
||||||
println!(
|
println!(
|
||||||
"The area of the rectangle is {} square pixels.",
|
"The area of the rectangle is {} square pixels.",
|
||||||
area(&rect1)
|
rect1.area()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn area(rectangle: &Rectangle) -> u32 {
|
|
||||||
rectangle.width * rectangle.height
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user