Exerpad
🔥 0
0 XP
Exercise 9 · Chapter: GenericsRequired+50 XP

Fix Generic Struct

This code defines a generic Container with a show method, but the impl block is missing its generic parameter! Fix it.

Fix the code so it prints:

Contains: 42

Hint: The impl block needs <T: std::fmt::Display> to match the struct.

rust
struct Container<T> {
item: T,
}

impl Container {
fn show(&self) {
println!("Contains: {}", self.item);
}
}

fn main() {
let c = Container { item: 42 };
c.show();
}
Output
Run your code to see the output here.