Creation of new numeric types seems to be a common pattern (I mean types that behave like numbers, but can’t be accidentally confused with other integer or float types, e.g.
The problem is that creation of such type using a tuple struct (
struct SomeUnit(f64)) requires boilerplate implementation of all basic numeric traits such as
A typical solution is to use a macro to generate trait implementations… but Rust already has feature for deriving “boring” implementations!
Therefore I suggest supporting
#[derive(Add, Sub, Mul, Div, PartialEq, PartialOrd)] (etc.) for tuple structs.
The behavior could be: When derive is used, if the first (the only?) element of the tuple struct supports the trait, then implement that trait using the first element’s implementation.