box-o-sand/rustbook/rectangles/src/main.rs

21 lines
361 B
Rust
Raw Normal View History

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 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:25:47 +00:00
println!("rect1 is {:?}", rect1);
2017-12-31 03:09:26 +00:00
println!(
"The area of the rectangle is {} square pixels.",
2017-12-31 15:03:50 +00:00
area(&rect1)
2017-12-31 03:09:26 +00:00
);
}
2017-12-31 15:03:50 +00:00
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
2017-12-31 03:09:26 +00:00
}