summaryrefslogtreecommitdiffstats
path: root/src/oop
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-11-07 05:53:30 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-11-07 05:53:30 +0300
commita3463adee5cfcbc422886653787fee12e594d5f6 (patch)
tree10befc5aa83ab2d1abb09862d70cfeef4d82d55d /src/oop
parent62dcfb1d9f95503f8eb8be1b29fa1d75bfcc27e2 (diff)
downloadrust-book-a3463adee5cfcbc422886653787fee12e594d5f6.tar.gz
rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.tar.bz2
rust-book-a3463adee5cfcbc422886653787fee12e594d5f6.zip
add: streams, thread2async, oop, blog
Diffstat (limited to '')
-rw-r--r--src/oop/Cargo.toml6
-rw-r--r--src/oop/src/lib.rs27
-rw-r--r--src/oop/src/main.rs40
3 files changed, 73 insertions, 0 deletions
diff --git a/src/oop/Cargo.toml b/src/oop/Cargo.toml
new file mode 100644
index 0000000..40f6a81
--- /dev/null
+++ b/src/oop/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "oop"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/oop/src/lib.rs b/src/oop/src/lib.rs
new file mode 100644
index 0000000..1f260c0
--- /dev/null
+++ b/src/oop/src/lib.rs
@@ -0,0 +1,27 @@
+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) {
+ // some code
+ }
+}
diff --git a/src/oop/src/main.rs b/src/oop/src/main.rs
new file mode 100644
index 0000000..5bd600e
--- /dev/null
+++ b/src/oop/src/main.rs
@@ -0,0 +1,40 @@
+use oop::{
+ Button,
+ Screen,
+ Draw,
+};
+
+struct SelectBox {
+ width: u32,
+ height: u32,
+ options: Vec<String>,
+}
+
+impl Draw for SelectBox {
+ fn draw(&self) {
+ // some code
+ }
+}
+
+fn main() {
+ let screen = Screen {
+ components: vec![
+ Box::new(SelectBox {
+ width: 75,
+ height: 10,
+ options: vec![
+ String::from("Yes"),
+ String::from("Maybe"),
+ String::from("No"),
+ ],
+ }),
+ Box::new(Button {
+ width: 50,
+ height: 10,
+ label: String::from("Ok"),
+ }),
+ ],
+ };
+
+ screen.run();
+}