trpl-zh-cn/listings/ch17-oop/listing-17-05/src/lib.rs

18 lines
275 B
Rust
Raw Normal View History

2022-02-06 16:43:51 +08:00
pub trait Draw {
fn draw(&self);
}
pub struct Screen {
pub components: Vec<Box<dyn Draw>>,
}
// ANCHOR: here
impl Screen {
pub fn run(&self) {
for component in self.components.iter() {
component.draw();
}
}
}
// ANCHOR_END: here