Hacker News new | past | comments | ask | show | jobs | submit login

Wrap/unwrap is free, and methods on the newtype are typically free as well.

I totally agree with your analysis, but in practice it's not always possible to merge implementation upstream and that's exactly what the article is about. Say you're working with a small scientific library and you want to serialize one of the data structures, but the authors haven't provided a Serde implementation. It'd be nice if you could upstream it, but if the authors aren't responsive you're forced to use a newtype. It sounds like this differs from Haskell, which (if I understand your comment) would allow you to implement it directly on the base type (with a warning).






Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: