feat: rbe 1.2.2.1: test case list w/ activity
This commit is contained in:
parent
ec8764f48d
commit
2e92e3463c
7
1-hello-world/formatted-printing/list-display/Cargo.lock
generated
Normal file
7
1-hello-world/formatted-printing/list-display/Cargo.lock
generated
Normal file
@ -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"
|
||||||
6
1-hello-world/formatted-printing/list-display/Cargo.toml
Normal file
6
1-hello-world/formatted-printing/list-display/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[package]
|
||||||
|
name = "list-display"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
29
1-hello-world/formatted-printing/list-display/src/main.rs
Normal file
29
1-hello-world/formatted-printing/list-display/src/main.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// Import the `fmt` module.
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
// Define a structuree named `List` containing a `Vec`.
|
||||||
|
struct List(Vec<i32>);
|
||||||
|
|
||||||
|
impl fmt::Display for List {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
// Create a reference to the Vec<i32> 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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user