Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Trait Parameter

Define a trait Describe with a method describe(&self) -> String. Implement it for Planet (with a name: String field). Write a function print_info that takes &impl Describe and prints the description. Test it with planet "Mars".

Expected output:

text
Planet: Mars

Hints:

  • fn print_info(item: &impl Describe) accepts any type with Describe
  • The describe method should return format!("Planet: {}", self.name)
rust
fn main() {
}