Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 11, 2019 20:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/74cb1966b24c912f9274d7a9c2c8b38e to your computer and use it in GitHub Desktop.
Save rust-play/74cb1966b24c912f9274d7a9c2c8b38e to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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