25 lines
427 B
Rust
25 lines
427 B
Rust
fn main() {
|
|
let mut rect = Rectangle {
|
|
width: 10,
|
|
height: 5,
|
|
};
|
|
println!("old area: {}", rect.area());
|
|
rect.inc_width(5);
|
|
println!("new area: {}", rect.area());
|
|
}
|
|
|
|
struct Rectangle {
|
|
width: u32,
|
|
height: u32,
|
|
}
|
|
|
|
impl Rectangle {
|
|
fn area(&self) -> u32 {
|
|
return self.width * self.height;
|
|
}
|
|
|
|
fn inc_width(&mut self, delta: u32) {
|
|
self.width += delta;
|
|
}
|
|
}
|