Why do I have to derive(Debug, Hash, PartialEq, Eq, Clone, Copy) when using the newtype pattern in @rustlang ?
Also, how about `let age = Years(5) + 1`;
https://doc.rust-lang.org/rust-by-example/generics/new_types.html …
-
-
I think it should inherit from the inner type because not inheriting leads to tons of boilerplate
-
That would be useful but is something different. We may eventually directly support that
- 1 more reply
New conversation -
-
-
Maybe using struct for newtype leads to this consequences. How about writing `pub type Days = new i64;` instead of `struct Days(i64);` to declare a newtype that inherits everything from i64 but is different to `pub type Days = new i64;`
-
That does not add any type safety, it is merely an alias. If your aim is documentating the code, it's fine... but a new type allow you to clearly define your intent and secure the usage of the type.
- 4 more replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.