29 lines
469 B
Rust
29 lines
469 B
Rust
#[derive(Debug)]
|
|
struct Rectangle {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
impl Rectangle {
|
|
fn area(&self) -> u32 {
|
|
self.width * self.height
|
|
}
|
|
|
|
fn add_height(&mut self) {
|
|
self.height += 1;
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let mut rect1 = Rectangle {
|
|
width: 30,
|
|
height: 50,
|
|
};
|
|
|
|
println!(
|
|
"The area of the rectangle is {} square pixels.",
|
|
rect1.area()
|
|
);
|
|
rect1.add_height();
|
|
println!("{:#?}", rect1);
|
|
} |