After reading quite a bit I haven't found much in the way how to decide whether to implement functionality as a trait with a default implementation or as a derive macro. It appears that the functionality of both is quite similar in many situations, so I'm wondering what considerations are taken when choosing to use one over the other.
- The main difference I see is that the default functionality of a trait can be overridden by the consumer of the trait, while this isn't possible for the output of a derive macro.
- The other big difference is that the macro has access to the token stream of the annotated item while a default trait implementation does not.
What are other practical differences between the two (i.e. not so concerned about technical details of how the two operate behind the scenes)?
Some possible use cases where this decision needs to be made are
If I know the default implementation of a trait will not need to be overridden is a derive macro preferred?
If I do not need access to the item's internals, is it preferred to use a trait with a default implementation?