diff options
Diffstat (limited to 'src/doc/book/listings/ch17-oop/listing-17-06')
3 files changed, 32 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch17-oop/listing-17-06/Cargo.lock b/src/doc/book/listings/ch17-oop/listing-17-06/Cargo.lock new file mode 100644 index 000000000..00d7b2182 --- /dev/null +++ b/src/doc/book/listings/ch17-oop/listing-17-06/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "gui" +version = "0.1.0" + diff --git a/src/doc/book/listings/ch17-oop/listing-17-06/Cargo.toml b/src/doc/book/listings/ch17-oop/listing-17-06/Cargo.toml new file mode 100644 index 000000000..9b816e766 --- /dev/null +++ b/src/doc/book/listings/ch17-oop/listing-17-06/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "gui" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/src/doc/book/listings/ch17-oop/listing-17-06/src/lib.rs b/src/doc/book/listings/ch17-oop/listing-17-06/src/lib.rs new file mode 100644 index 000000000..63a8907d3 --- /dev/null +++ b/src/doc/book/listings/ch17-oop/listing-17-06/src/lib.rs @@ -0,0 +1,20 @@ +pub trait Draw { + fn draw(&self); +} + +// ANCHOR: here +pub struct Screen<T: Draw> { + pub components: Vec<T>, +} + +impl<T> Screen<T> +where + T: Draw, +{ + pub fn run(&self) { + for component in self.components.iter() { + component.draw(); + } + } +} +// ANCHOR_END: here |