sunface / rust-by-practice

Learning Rust By Practice, narrowing the gap between beginner and skilled-dev through challenging examples, exercises and projects.

Home Page:https://practice.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question on 10.3 Traits, Exercise 6 Returning Types that Implement Traits

dycw opened this issue · comments

Hi @sunface , thanks for a great library!

I'm a little surprised by the answer, I certainly don't think it respects the spirit of the question...

Spoiler warning!
fn random_animal(random_number: f64) -> impl Animal {
    if random_number < 0.5 {
        Sheep {}
    } else {
        Sheep {}
    }
}

For a beginner, I can't figure out what the answer should be however - help needed please.