From a3463adee5cfcbc422886653787fee12e594d5f6 Mon Sep 17 00:00:00 2001 From: hybrid Date: Sat, 7 Nov 2026 05:53:30 +0300 Subject: add: streams, thread2async, oop, blog --- src/oop/Cargo.toml | 6 ++++++ src/oop/src/lib.rs | 27 +++++++++++++++++++++++++++ src/oop/src/main.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 src/oop/Cargo.toml create mode 100644 src/oop/src/lib.rs create mode 100644 src/oop/src/main.rs (limited to 'src/oop') 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>, +} + +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, +} + +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(); +} -- cgit v1.3.1