SHARE
TWEET

Untitled

a guest Apr 21st, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trait Rendered {
  2.     fn render(&mut self);
  3. }
  4.  
  5. struct TextLabel {
  6. }
  7.  
  8. impl Rendered for TextLabel {
  9.     fn render(&mut self) {
  10.         println!("TextLabel");
  11.     }
  12. }
  13.  
  14. struct ColorPot {
  15. }
  16.  
  17. impl Rendered for ColorPot {
  18.     fn render(&mut self) {
  19.         println!("ColorPot");
  20.     }
  21. }
  22.  
  23. pub fn main() {
  24.     let mut widgets: Vec<Box<Rendered>> = Vec::new();
  25.     widgets.push(Box::new(TextLabel {}));
  26.     widgets.push(Box::new(ColorPot {}));
  27. //  let mut widgets: Vec<Box<Rendered>> = vec!(Box::new(TextLabel {}), Box::new(ColorPot {}));
  28.     for w in &mut widgets {
  29.         w.render();
  30.     }
  31. }
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