Exercise 7 · Chapter: TraitsRequired+50 XP
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:
Planet: Mars
Hints:
fn print_info(item: &impl Describe)accepts any type withDescribe- The
describemethod should returnformat!("Planet: {}", self.name)
rust
fn main() {
}
Output
Run your code to see the output here.