struct rect

This commit is contained in:
Dan Buch 2017-12-31 10:03:50 -05:00
parent cead47060a
commit 68db30f013
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

@ -1,12 +1,17 @@
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = (30, 50);
let rect1 = Rectangle { width: 30, height: 50 };
println!(
"The area of the rectangle is {} square pixels.",
area(rect1)
area(&rect1)
);
}
fn area(dimensions: (u32, u32)) -> u32 {
dimensions.0 * dimensions.1
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}