You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C-NEWTYPE-HIDE neglects to mention something that I feel is quite important:
Enumerate<Skip<I>> does not just implement Iterator; it may also implement some or all of Debug, Clone, FusedIterator, ExactSizeIterator and DoubleEndedIterator.
By wrapping the Enumerate<Skip<I>> in a newtype, you lose those implementations. (This is also my biggest concern with practical usage of impl Trait, though I definitely want it.)
Thus, I say that for private code, wrapping things in a newtype like that is a mild anti-pattern as it fights against various optimisations and use cases. (Use a type alias, by all means; approximately all the benefits without any of the maintenance cost.)
For public code, wrapping such implementation details that could conceivably change in a newtype is the responsible and elegant thing to do, but the guideline needs to mention this detail about other traits, and that you should also add to your code most or all of these—
We could link to other guidelines suggesting appropriate traits are implemented from this one, which I think should cover ensuring a newtype is appropriately usable.
C-NEWTYPE-HIDE neglects to mention something that I feel is quite important:
Enumerate<Skip<I>>
does not just implementIterator
; it may also implement some or all ofDebug
,Clone
,FusedIterator
,ExactSizeIterator
andDoubleEndedIterator
.By wrapping the
Enumerate<Skip<I>>
in a newtype, you lose those implementations. (This is also my biggest concern with practical usage ofimpl Trait
, though I definitely want it.)Thus, I say that for private code, wrapping things in a newtype like that is a mild anti-pattern as it fights against various optimisations and use cases. (Use a type alias, by all means; approximately all the benefits without any of the maintenance cost.)
For public code, wrapping such implementation details that could conceivably change in a newtype is the responsible and elegant thing to do, but the guideline needs to mention this detail about other traits, and that you should also add to your code most or all of these—
(While we’re here: the
Result
suffix inMyTransformResult
should be killed with prejudice.)The text was updated successfully, but these errors were encountered: