trpl-zh-cn/listings/ch17-oop/listing-17-08/src/lib.rs
2022-02-06 16:43:51 +08:00

28 lines
421 B
Rust
Executable File

pub trait Draw {
fn draw(&self);
}
pub struct Screen {
pub components: Vec<Box<dyn Draw>>,
}
impl Screen {
pub fn run(&self) {
for component in self.components.iter() {
component.draw();
}
}
}
pub struct Button {
pub width: u32,
pub height: u32,
pub label: String,
}
impl Draw for Button {
fn draw(&self) {
// code to actually draw a button
}
}