Struct method woop

cat-town
Dan Buch 3 years ago
parent d64444550a
commit 1622e4bcea
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -4,20 +4,20 @@ struct Rectangle {
height: u32,
}
impl Rectangle {
fn area(&self) -> u32 {
self.width * self.height
}
}
fn main() {
let rect1 = Rectangle {
width: 30,
height: 50,
};
println!("rect1 is {:#?}", rect1);
println!(
"The area of the rectangle is {} square pixels.",
area(&rect1)
rect1.area()
);
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}

Loading…
Cancel
Save