Created
April 11, 2019 20:49
-
-
Save rust-play/74cb1966b24c912f9274d7a9c2c8b38e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment