File tree Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Expand file tree Collapse file tree 1 file changed +42
-1
lines changed Original file line number Diff line number Diff line change 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+
120fn 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+ // }
You can’t perform that action at this time.
0 commit comments