Guest User

Untitled

a guest
Jul 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. struct Square {
  2. length: i32,
  3. }
  4.  
  5. impl Square {
  6. fn new(length: i32) -> Square {
  7. Square { length }
  8. }
  9.  
  10. fn area(&self) -> i32 {
  11. self.length * self.length
  12. }
  13. }
  14.  
  15.  
  16. struct Rectangle {
  17. width: i32,
  18. height: i32,
  19. }
  20.  
  21. impl Rectangle {
  22. fn new(width: i32, height: i32) -> Rectangle {
  23. Rectangle { width, height}
  24. }
  25.  
  26. fn area(&self) -> i32 {
  27. self.width * self.height
  28. }
  29. }
  30.  
  31. fn main() {
  32. let rect = Rectangle::new(30, 50);
  33. let sqr = Square::new(30);
  34.  
  35. println!("The area of rectangle is {}.", rect.area());
  36. println!("The area of square is {}.", sqr.area());
  37. }
Add Comment
Please, Sign In to add comment