Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

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:

text
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();
}