4 ms·
I don't understand why the author wants to access fields from a trait. They can be accessed by the trait implementations, which makes sense, because the fields
by whyever 10y ago
I don't understand why the author wants to access fields from a trait. They can be accessed by the trait implementations, which makes sense, because the fields depend on the type.
- steveklabnik 10y agoYou should check out the RFC they linked; there are good reasons to enable this.
- whyever 10y agoThanks! Here are the reason why trait fields are preferable over accessors in case anyone else is wondering: 1. The borrow checker assumes accessors can do anything, freezing all other fields. This does not happen with trait fields. 2. Accessors have to use dynamic dispatch in case of trait objects, resulting in worse performance.