Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Rectangle {
- width: f64,
- height: f64,
- }
- impl Rectangle {
- fn area(&self) -> f64 {
- self.width * self.height
- }
- fn scale(&mut self, factor: f64) {
- self.width *= factor;
- self.height *= factor;
- }
- }
- fn main() {
- let mut r = Rectangle{ width: 5.0, height: 2.5 };
- println!("Area of rectangle is {}", r.area());
- r.scale(1.25);
- println!("Area of scaled up rectangle is {}", r.area());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement