mcarton/rust-derivative

Allow global bound declarations

jakubdabek opened this issue · 0 comments

Use case:

#[derive(Derivative)]
#[derivative(Debug, Default, Clone)]
pub struct FooConfig<C> {
  bar: bool,
  _c: PhantomData<C>,
}

#[derive(Derivative)]
#[derivative(Debug(bound = ""), Clone(bound = ""), Default(bound = ""))]
pub struct Foo<C> {
    config: FooConfig<C>,
}

The Config struct doesn't require additional bounds, as PhantomData is automatically detected.
Foo also shouldn't care about C in this example, but the bounds are added, and you have to remove them for each trait you're deriving.

I propose to create a method of specifying bounds for all derived traits, like:

#[derive(Derivative)]
#[derivative(bound = "")]
#[derivative(Debug, Clone, Default)]
pub struct Foo<C> {
    config: FooConfig<C>,
}

This would also be useful in a case like in #1 for multiple derives (a global Ix: IndexType bound).