3 ms·
Good point! Using dyn Trait syntax (aka, dynamic dispatch) uses type erasure and is kind-of like Go and Java's implementation of Generics I guess. You can defin
by davidhyde 4y ago
Good point! Using dyn Trait syntax (aka, dynamic dispatch) uses type erasure and is kind-of like Go and Java's implementation of Generics I guess. You can definitely use that in Rust but the article is about impl Trait syntax which is for concrete types (not type erased)
- estebank 4y agoThe only nitpick I'd have is that `impl Trait` doesn't necessarily imply a concrete type. Or rather it does, but in so far `Box<dyn Trait>` is also a concrete type :) That means that you can have a function that returns `-> impl Trait` with a concrete implementation because it has a single return value, but if you add a second and don't want to create an enum for a simple version of static dispatch, you can change the returned values to be trait objects and the callers don't break.