From 2e92e3463cc8882347efd35727e64070df25ca1f Mon Sep 17 00:00:00 2001 From: Nak0_x Date: Sat, 5 Sep 2026 00:34:55 +0200 Subject: [PATCH] feat: rbe 1.2.2.1: test case list w/ activity --- .../list-display/Cargo.lock | 7 +++++ .../list-display/Cargo.toml | 6 ++++ .../list-display/src/main.rs | 29 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 1-hello-world/formatted-printing/list-display/Cargo.lock create mode 100644 1-hello-world/formatted-printing/list-display/Cargo.toml create mode 100644 1-hello-world/formatted-printing/list-display/src/main.rs diff --git a/1-hello-world/formatted-printing/list-display/Cargo.lock b/1-hello-world/formatted-printing/list-display/Cargo.lock new file mode 100644 index 0000000..f4937d4 --- /dev/null +++ b/1-hello-world/formatted-printing/list-display/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "list-display" +version = "0.1.0" diff --git a/1-hello-world/formatted-printing/list-display/Cargo.toml b/1-hello-world/formatted-printing/list-display/Cargo.toml new file mode 100644 index 0000000..3b26e26 --- /dev/null +++ b/1-hello-world/formatted-printing/list-display/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "list-display" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/1-hello-world/formatted-printing/list-display/src/main.rs b/1-hello-world/formatted-printing/list-display/src/main.rs new file mode 100644 index 0000000..17a2051 --- /dev/null +++ b/1-hello-world/formatted-printing/list-display/src/main.rs @@ -0,0 +1,29 @@ +// Import the `fmt` module. +use std::fmt; + +// Define a structuree named `List` containing a `Vec`. +struct List(Vec); + +impl fmt::Display for List { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + // Create a reference to the Vec stored in the List struct. + let vec = &self.0; + + write!(f, "[")?; + + // Iterate over `v` in `vec` while enumerating the iteration + // index in `index`. + for (index, v) in vec.iter().enumerate() { + if index != 0 { write!(f, ", ")?; } + write!(f, "{index}: {v}")?; + } + + // Close the opend bracket and return a fmt::Result value. + write!(f, "]") + } +} + +fn main() { + let v = List(vec![1, 2, 3]); + println!("{}", v); +}