Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Element {
- fn handle(&mut self, ui: &mut UI) {
- }
- }
- struct UI {
- elements: Vec<Box<Element>>
- }
- impl UI {
- fn handle(&mut self, index: usize) {
- let mut element = self.elements.get_mut(index).unwrap();
- element.handle(self);
- }
- }
- struct Thing;
- impl Element for Thing {
- fn handle(&mut self, ui: &mut UI) {
- println!("test");
- }
- }
- fn main() {
- let mut ui = UI { elements: Vec::new() };
- ui.elements.push(Box::new(Thing));
- ui.handle(0);
- }
Add Comment
Please, Sign In to add comment