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
First of all, thanks for the great summary of the orphan rule and its surrounding issues, it's been very helpful for me as I tried to understand the overall topic.
So, what is the current consensus on this subject? Is it such a non-starter that it's not even worth mentioning, or was it not included here for some other reason? Because, while I'm definitely a beginner in Rust, to me the whole thing seems pretty tempting: you do not need to write delegate methods pretty much at all, you can implement new traits on the newtype as normal, and you can also use the trait implementations of the wrapped type with the dereference operator (*).
The text was updated successfully, but these errors were encountered:
Excellent point, I did not think about Deref at all when I was doing these write ups.
My vague, mostly baseless impression is that using Deref on newtypes is par for the course today (despite the various downsides), but nobody believes that Deref is part of the ideal solution for any of these use cases, so it'll probably start to fade away as features like specialization and delegation get fully implemented and stabilized (assuming they really do solve these problems).
That said, I can't recall anyone ever proposing an "ideal solution" that involved Deref, so I can't rule out the possibility that we've all missed something. And half the point of this repo is to gather concrete use cases so we can actually answer questions like "are there any important use cases specialization and delegation can't solve?" More ideas are always welcome.
First of all, thanks for the great summary of the orphan rule and its surrounding issues, it's been very helpful for me as I tried to understand the overall topic.
One thing the text and linked issues do not seem to mention is using Deref for newtypes to avoid boilerplate. Now I understand that this topic might be controversial, the unofficial rust pattern repo for instance mentions implementing Deref in this case as an anti-pattern, but on the other hand the much more recent second edition of the Rust introductory book now mentions using Deref on newtypes as a practical solution.
So, what is the current consensus on this subject? Is it such a non-starter that it's not even worth mentioning, or was it not included here for some other reason? Because, while I'm definitely a beginner in Rust, to me the whole thing seems pretty tempting: you do not need to write delegate methods pretty much at all, you can implement new traits on the newtype as normal, and you can also use the trait implementations of the wrapped type with the dereference operator (*).
The text was updated successfully, but these errors were encountered: