trpl-zh-cn/listings/ch05-using-structs-to-structure-related-data/listing-05-10/src/main.rs
2022-02-06 16:43:51 +08:00

21 lines
326 B
Rust
Executable File

struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = Rectangle {
width: 30,
height: 50,
};
println!(
"The area of the rectangle is {} square pixels.",
area(&rect1)
);
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}