Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Rendered {
- fn render(&mut self);
- }
- struct TextLabel {
- }
- impl Rendered for TextLabel {
- fn render(&mut self) {
- println!("TextLabel");
- }
- }
- struct ColorPot {
- }
- impl Rendered for ColorPot {
- fn render(&mut self) {
- println!("ColorPot");
- }
- }
- pub fn main() {
- let mut widgets: Vec<Box<Rendered>> = Vec::new();
- widgets.push(Box::new(TextLabel {}));
- widgets.push(Box::new(ColorPot {}));
- // let mut widgets: Vec<Box<Rendered>> = vec!(Box::new(TextLabel {}), Box::new(ColorPot {}));
- for w in &mut widgets {
- w.render();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement