jingxun
3 years ago
1 changed files with 36 additions and 0 deletions
@ -0,0 +1,36 @@ |
|||
// #[derive(Debug)]
|
|||
struct Rectangle { |
|||
width: u32, |
|||
height: u32, |
|||
} |
|||
|
|||
impl Rectangle { |
|||
fn area(&self) -> u32 { |
|||
self.width * self.height |
|||
} |
|||
} |
|||
|
|||
fn main() { |
|||
let rect = (20, 30); |
|||
println!("The area of the rect is {}", area(rect)); |
|||
let rect1 = Rectangle { |
|||
width: 14, |
|||
height: 37, |
|||
}; |
|||
println!("The area of the rect is {}", area_struct(&rect1)); |
|||
// dbg!(&rect1);
|
|||
// println!("rect1 is {:#?}",rect1)
|
|||
let rect2 = Rectangle{ |
|||
width:23, |
|||
height:59 |
|||
}; |
|||
println!("The area of the rect is {}",rect2.area()); |
|||
} |
|||
|
|||
fn area(dims: (u32, u32)) -> u32 { |
|||
dims.0 * dims.1 |
|||
} |
|||
|
|||
fn area_struct(rect: &Rectangle) -> u32 { |
|||
rect.width * rect.height |
|||
} |
Loading…
Reference in new issue