Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. struct Rectangle {
  2. width: f64,
  3. height: f64,
  4. }
  5.  
  6. impl Rectangle {
  7. fn area(&self) -> f64 {
  8. self.width * self.height
  9. }
  10.  
  11. fn scale(&mut self, factor: f64) {
  12. self.width *= factor;
  13. self.height *= factor;
  14. }
  15. }
  16.  
  17. fn main() {
  18. let mut r = Rectangle{ width: 5.0, height: 2.5 };
  19. println!("Area of rectangle is {}", r.area());
  20. r.scale(1.25);
  21. println!("Area of scaled up rectangle is {}", r.area());
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement