6 ms·
Okay, I was being a bit hyperbolic and I'd rather not go back and forth, but I do really hate the newtype pattern. I'm not sure why they don't introduce somethi
by nmilo 3y ago
Okay, I was being a bit hyperbolic and I'd rather not go back and forth, but I do really hate the newtype pattern. I'm not sure why they don't introduce something like what Go has, like `type UserID = uint32`.
- deleted 3y ago[deleted]
- jcrites 3y agoRust has that, it's called a type alias: https://doc.rust-lang.org/reference/items/type-aliases.html https://doc.rust-lang.org/reference/items/type-aliases.html I'm not familiar with that Go feature, but in Rust it's just introducing another name for a type. I've usually seen it used to introduce simpler names for complex types.
- duped 3y agoType aliases and new types are two subtly different features. The new type pattern allows you to provide new impls for the underlying type (it is a new type after all) while the type alias is pure sugar where type T = U allows the string T to be substituted for U in any place where T is imported. If U is a foreign type you cannot provide new trait impls for it.