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;andstruct Cat; - Implement
Speakfor each withimpl Speak for Dog { ... }
rust
fn main() {
}