Implement area
using a method
This commit is contained in:
parent
d9963ced18
commit
a8248ed120
1 changed files with 11 additions and 3 deletions
|
@ -4,12 +4,20 @@ struct Rectangle {
|
|||
height: u32,
|
||||
}
|
||||
|
||||
impl Rectangle {
|
||||
fn area(&self) -> u32 {
|
||||
self.width * self.height
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let scale = 2;
|
||||
let rect1 = Rectangle {
|
||||
width: dbg!(30 * scale),
|
||||
width: 30,
|
||||
height: 50,
|
||||
};
|
||||
|
||||
dbg!(&rect1);
|
||||
println!(
|
||||
"The area of the rectangle is {} square pixels.",
|
||||
rect1.area()
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue