summaryrefslogtreecommitdiffstats
path: root/src/supertraits
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.cc>2026-11-11 17:16:48 +0300
committerhybrid <hybrid@hybridlabs.cc>2026-11-11 17:16:48 +0300
commit9dea46b5e66eb54746b251d8950b2367c49be23d (patch)
treefdebf3880f2f25a1351a220e771da84ea32f07e2 /src/supertraits
parent59e457f7d6267ac2591837085b388d7c15ed2004 (diff)
downloadrust-book-main.tar.gz
rust-book-main.tar.bz2
rust-book-main.zip
add: supertraits, ext_traits, pancakes, hello, hello_macromain
Diffstat (limited to '')
-rw-r--r--src/supertraits/Cargo.toml6
l---------src/supertraits/src/.#main.rs1
-rw-r--r--src/supertraits/src/main.rs42
3 files changed, 49 insertions, 0 deletions
diff --git a/src/supertraits/Cargo.toml b/src/supertraits/Cargo.toml
new file mode 100644
index 0000000..3c073ab
--- /dev/null
+++ b/src/supertraits/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "supertraits"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/supertraits/src/.#main.rs b/src/supertraits/src/.#main.rs
new file mode 120000
index 0000000..e886a79
--- /dev/null
+++ b/src/supertraits/src/.#main.rs
@@ -0,0 +1 @@
+hybrid@polar.514225:1793336784 \ No newline at end of file
diff --git a/src/supertraits/src/main.rs b/src/supertraits/src/main.rs
new file mode 100644
index 0000000..3053c5a
--- /dev/null
+++ b/src/supertraits/src/main.rs
@@ -0,0 +1,42 @@
+use std::fmt;
+
+trait OutlinePrint: fmt::Display {
+ fn outline_print(&self) {
+ let output = self.to_string();
+ let len = output.len();
+
+ println!("{}", "*".repeat(len + 4));
+ println!("*{}*", " ".repeat(len + 2));
+ println!("* {output} *");
+ println!("*{}*", " ".repeat(len + 2));
+ println!("{}", "*".repeat(len + 4));
+ }
+}
+
+struct Point {
+ x: i32,
+ y: i32,
+}
+
+impl Point {
+ fn new() -> Point {
+ Point {
+ x: 0,
+ y: 0,
+ }
+ }
+}
+
+impl fmt::Display for Point {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "({}, {})" , self.x, self.y)
+ }
+}
+
+impl OutlinePrint for Point {}
+
+fn main() {
+ let point = Point::new();
+
+ OutlinePrint::outline_print(&point);
+}