Skip to content

Commit 319b4d1

Browse files
committed
complete the challange of rectangles with
1 parent edb7eef commit 319b4d1

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

projects/rectangles/src/main.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
1+
#[derive(Debug)]
2+
struct Rectangle {
3+
width: u32,
4+
height: u32,
5+
}
6+
7+
impl Rectangle {
8+
fn area(&self) -> u32 {
9+
self.width * self.height
10+
}
11+
}
12+
13+
fn rectangle_builder(width: u32, height: u32) -> Rectangle {
14+
Rectangle {
15+
height,
16+
width,
17+
}
18+
}
19+
120
fn main() {
2-
println!("Hello, world!");
21+
// * Step 1:
22+
// let width = 100;
23+
// let height = 140;
24+
25+
// let area = rectangle_area(width, height);
26+
27+
// * Step 2:
28+
// let rect1 = Rectangle { height: 140, width: 100 };
29+
// let area = rect1.area();
30+
31+
// * Step 3:
32+
33+
let rect1 = rectangle_builder(100, 140);
34+
35+
let area = rect1.area();
36+
37+
// println!("{:#?}", rect1);
38+
println!("the area of rectangle is : {area}");
39+
dbg!(&rect1);
340
}
41+
42+
// fn rectangle_area(width: u32, height: u32) -> u32 {
43+
// width * height
44+
// }

0 commit comments

Comments
 (0)