Why does idiomatic Rust code pervasively parameterize over trait bounds, rather than simply taking trait objects? The speed argument smacks of premature optimization; what are the other reasons?
-
-
Replying to @froydnj
I used to feel this way, then joined Team impl Trait, which is ergonomically very similar to Trait objects without the object safety or performance issue of trait objects.
1 reply 0 retweets 3 likes -
until you find out how much worse the compile time is when you monomorphize all the things
1 reply 0 retweets 2 likes -
Replying to @withoutboats @froydnj
We should be able to do better. Many monomorphizations aren't creating very different functions.
1 reply 0 retweets 0 likes -
I thought someone also proposed that the compiler should be able to handle simple cases like `fn foo<T: AsRef<str>>(t: T) {}` where it could generate simple generic functions that call a concrete function `fn foo(t: &str) {}` with the actual code.
2 replies 0 retweets 3 likes
Yeah it was one of my very first proposals when I joined rust.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.