2017-12-31 15:25:47 +00:00
|
|
|
#[derive(Debug)]
|
2017-12-31 15:03:50 +00:00
|
|
|
struct Rectangle {
|
|
|
|
width: u32,
|
|
|
|
height: u32,
|
|
|
|
}
|
|
|
|
|
2017-12-31 15:30:54 +00:00
|
|
|
impl Rectangle {
|
|
|
|
fn area(&self) -> u32 {
|
|
|
|
self.width * self.height
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-31 03:09:26 +00:00
|
|
|
fn main() {
|
2017-12-31 15:03:50 +00:00
|
|
|
let rect1 = Rectangle { width: 30, height: 50 };
|
2017-12-31 03:09:26 +00:00
|
|
|
|
2017-12-31 15:26:38 +00:00
|
|
|
println!("rect1 is {:#?}", rect1);
|
2017-12-31 15:25:47 +00:00
|
|
|
|
2017-12-31 03:09:26 +00:00
|
|
|
println!(
|
|
|
|
"The area of the rectangle is {} square pixels.",
|
2017-12-31 15:30:54 +00:00
|
|
|
rect1.area()
|
2017-12-31 03:09:26 +00:00
|
|
|
);
|
|
|
|
}
|