I have two traits in a hierarchy: Animal and Bird. How can I create a Chicken that implements Bird?
trait Animal {
fn noise(&self) -> String;
fn print_noise(&self) {
print!("{}", self.noise());
}
}
trait Bird: Animal {
fn noise(&self) -> String {
"chirp"
}
}
struct Chicken {}
impl Bird for Chicken {}
When I try to compile, I get:
error[E0277]: the trait bound `Chicken: Animal` is not satisfied
--> src/lib.rs:16:6
|
16 | impl Bird for Chicken {}
| ^^^^ the trait `Animal` is not implemented for `Chicken`
I don't want to implement Animal before Bird, because I want Chicken to inherit the noise function from Bird.