4 ms·
What about impl Trait then? In that case traits make sense without pointers. To me traits are like a definition of capabilities. A way to duck type things.
by iTokio 2y ago
What about impl Trait then?
In that case traits make sense without pointers.
To me traits are like a definition of capabilities. A way to duck type things.
- kaoD 2y ago"Trait objects" is lingo for `dyn Trait`. They are a distinct thing from just "trait". They allow virtual dispatch at runtime. See https://doc.rust-lang.org/reference/types/trait-object.html https://doc.rust-lang.org/reference/types/trait-object.html (`dyn Trait`, runtime dynamic dispatch) vs https://doc.rust-lang.org/reference/types/impl-trait.html https://doc.rust-lang.org/reference/types/impl-trait.html (`impl Trait`, compile-time monomorphization)
- LoganDark 2y ago`impl Trait` is sort like of syntax sugar for generics (this is not the full story, for example TAIT/type_alias_impl_trait... but it's close enough). It's monomorphized just like generics are. If you have a method that takes an `impl Trait` then a new copy of the method will be emitted by the compiler for each unique type you pass to that `impl Trait` parameter. Traits conceptually are kind of like definitions of capabilities. So you're not really wrong about that, that understanding probably may even help you.