struct with fields

This commit is contained in:
Tyrel Souza 2023-02-26 23:51:24 -05:00
parent 099a55d642
commit 92b1c38688
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E

View File

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