From 92b1c386880ded30a46d45b5908db48df5eb0134 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Sun, 26 Feb 2023 23:51:24 -0500 Subject: [PATCH] struct with fields --- rectangles/src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/rectangles/src/main.rs b/rectangles/src/main.rs index a587139..50de859 100644 --- a/rectangles/src/main.rs +++ b/rectangles/src/main.rs @@ -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 } \ No newline at end of file