SHARE
TWEET

Untitled

a guest Feb 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top