richardanaya / tour_of_rust

A tour of rust's language features
https://tourofrust.com
MIT License
882 stars 202 forks source link

Generic Functions enable static dispatch: how? #360

Open jtwilliamss opened 3 years ago

jtwilliamss commented 3 years ago

I understand Generic Functions enable

  1. static dispatch (https://tourofrust.com/84_en.html) instead of / over
  2. dynamic dispatch (https://tourofrust.com/81_en.html).

What I do not understand is how.

Specifically: how does the compiler better know the "real type" (of the NoiseMaker trait) with (1.) over (2.)?

[Is this "how does Rust work?" question outside the scope of an issue submission for this project?]

ps. tour_of_rust is my favorite "learning as a Rust newbie" I've found thus far. Thanks so much for putting this together.

jtwilliamss commented 3 years ago

Further discussion here:

https://www.reddit.com/r/rust/comments/lv3eb2/hey_rustaceans_got_an_easy_question_ask_here_92021/gpdp9i2/?utm_source=reddit&utm_medium=web2x&context=3

jtwilliamss commented 3 years ago

My potentially-overly-summarized conclusion (see reddit.com discussion above for more details): dyn specifically disables static dispatch.

In any case, closing this issue.