Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Animal Speak

Define a trait Speak with a method sound(&self) -> &str. Implement it for Dog (returns "Woof!") and Cat (returns "Meow!"). Print both.

Expected output:

text
Dog says: Woof!
Cat says: Meow!

Hints:

  • Define trait Speak { fn sound(&self) -> &str; }
  • Create empty structs: struct Dog; and struct Cat;
  • Implement Speak for each with impl Speak for Dog { ... }
rust
fn main() {
}