-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New derives: From and Deref #2026
Copy link
Copy link
Open
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.T-libsRelevant to the library team, which will review and decide on the RFC.Relevant to the library team, which will review and decide on the RFC.
Description
Activity
Metadata
Metadata
Assignees
Labels
T-langRelevant to the language team, which will review and decide on the RFC.Relevant to the language team, which will review and decide on the RFC.T-libsRelevant to the library team, which will review and decide on the RFC.Relevant to the library team, which will review and decide on the RFC.
It's often useful to wrap a single type into a new one, to be able to add new methods, provide more documentation and possibly type safety.
For example,
This way if the units are used incorrectly we get a type error. Fortunately there is no space overhead as well. This is very similar to
newtypein Haskell.I'm proposing that we consider being able to derive
Fromand possiblyDereffor structs with exactly one field. For the above example, adding#[derive(From, Deref)]aboveIncheswould generate the code:These or similar derives would significantly reduce boilerplate when creating wrapper types, thus encouraging their use.
EDIT: fixed i32 => f32