2023-01-14 18:57:39 +00:00
|
|
|
fn main() {
|
2023-01-14 21:04:26 +00:00
|
|
|
let mut rect = Rectangle {
|
|
|
|
width: 10,
|
|
|
|
height: 5,
|
|
|
|
};
|
|
|
|
println!("old area: {}", rect.area());
|
|
|
|
rect.inc_width(5);
|
|
|
|
println!("new area: {}", rect.area());
|
2023-01-14 20:37:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 21:04:26 +00:00
|
|
|
struct Rectangle {
|
|
|
|
width: u32,
|
|
|
|
height: u32,
|
2023-01-14 20:37:45 +00:00
|
|
|
}
|
2023-01-14 18:57:39 +00:00
|
|
|
|
2023-01-14 21:04:26 +00:00
|
|
|
impl Rectangle {
|
|
|
|
fn area(&self) -> u32 {
|
|
|
|
return self.width * self.height;
|
2023-01-14 20:37:45 +00:00
|
|
|
}
|
2023-01-14 20:21:59 +00:00
|
|
|
|
2023-01-14 21:04:26 +00:00
|
|
|
fn inc_width(&mut self, delta: u32) {
|
|
|
|
self.width += delta;
|
2023-01-14 20:37:45 +00:00
|
|
|
}
|
2023-01-14 18:57:39 +00:00
|
|
|
}
|