Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement