Guest User

Untitled

a guest
Jun 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. trait Element {
  2. fn handle(&mut self, ui: &mut UI) {
  3.  
  4. }
  5. }
  6.  
  7. struct UI {
  8. elements: Vec<Box<Element>>
  9. }
  10.  
  11. impl UI {
  12. fn handle(&mut self, index: usize) {
  13. let mut element = self.elements.get_mut(index).unwrap();
  14. element.handle(self);
  15. }
  16. }
  17.  
  18. struct Thing;
  19.  
  20. impl Element for Thing {
  21. fn handle(&mut self, ui: &mut UI) {
  22. println!("test");
  23. }
  24. }
  25.  
  26. fn main() {
  27. let mut ui = UI { elements: Vec::new() };
  28. ui.elements.push(Box::new(Thing));
  29. ui.handle(0);
  30. }
Add Comment
Please, Sign In to add comment