derive_more icon indicating copy to clipboard operation
derive_more copied to clipboard

Implemented `#[skip]` for the `Add` derive

Open ErmitaVulpe opened this issue 5 months ago • 1 comments
trafficstars

Resolves #437

Synopsis

As outlined in #437 it isn't possible to derive Add for structs containing zero sized fields

Example:

#[derive(Add)] // method not found in `PhantomData<T>`
struct TupleWithZst<T>(i32, PhantomData<T>);

#[derive(Add)] // method not found in `PhantomData<T>`
struct StructWithZst<T> {
    x: i32
    _marker: PhantomData<T>,
}

Solution

Added a #[skip] attribute that allows to skip zero sized fields like so:

#[derive(Add)]
struct TupleWithZst<T>(i32, #[add(skip)] PhantomData<T>);

#[derive(Add)]
struct StructWithZst<T> {
    x: i32,
    #[add(skip)]
    _marker: PhantomData<T>,
}

Checklist

  • [x] Documentation is updated (if required)
  • [x] Tests are added/updated (if required)
  • [x] CHANGELOG entry is added (if required)

ErmitaVulpe avatar May 22 '25 15:05 ErmitaVulpe