Advertisement
cwchen

[Rust] Basketball class, implementing both Color and Shape

Sep 4th, 2017
3,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.57 KB | None | 0 0
  1. pub struct Basketball {
  2.      color: Box<Color>,
  3.      shape: Box<Shape>,
  4. }
  5.  
  6. impl Basketball {
  7.     pub fn new() -> Basketball {
  8.         let orange = Box::new(Orange{});
  9.         let ball = Box::new(Ball{});
  10.         Basketball{ color: orange, shape: ball }
  11.     }
  12. }
  13.  
  14. impl Color for Basketball {
  15.     fn color<'a>(&self) -> &'a str {
  16.         self.color.color()
  17.     }
  18. }
  19.  
  20. impl Shape for Basketball {
  21.     fn shape<'a>(&self) -> &'a str {
  22.         self.shape.shape()
  23.     }
  24. }
  25.  
  26. impl Item for Basketball {
  27.     fn name<'a>(&self) -> &'a str {
  28.         "basketball"
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement