derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Allow ignore in more derive macros

Open petersf-libre opened this issue 5 years ago • 0 comments
trafficstars

The #[from(ignore)] syntax could be helpful in other traits as well. The ops such as Add are the case I specifically was looking for, but it's not hard to imagine it could be useful in a wide number of places.

For example, in the following type:

struct NamedInt {
    value: i64,
    name: String,
}

it would be nice to be able to do the following:

#[derive(Add)]
struct NamedInt {
    value: i64,
    #[add(ignore)]
    name: String,
}

One consideration is how syntax would work with many derived traits at once. I'm not very familiar with rust's attribute syntax so I might be missing something, but one obvious situation from the above example is:

#[derive(Add, Div, Mul, Sub)]
struct NamedInt {
    value: i64,
    name: String,
}

Entering in #[trait(ignore)] for every trait could quickly become cumbersome. Adopting something like the #[allow()] syntax might be helpful here:

#[derive(Add, Div, Mul, Sub)]
struct NamedInt {
    value: i64,
    #[derive_ignore(add, div, mul, sub)]
    name: String,
}

I'm hoping that, given that something is already implemented for From, this should be a fairly easy change to make, but again I'm not very experienced with macros so I could be missing a complication. If I have extra time soon I might take a crack at a PR.

petersf-libre avatar Aug 01 '20 04:08 petersf-libre