derive_more
derive_more copied to clipboard
Support adding an arbitrary attribute on top of `Constructor` impl
Hi,
as discussed in https://github.com/nrxus/faux/issues/58 and brought forward by @nrxus, it would be nice if #[derive(Constructor)] could support arbitrary attributes. That way, we could use it in conjunction with faux.
@nrxus proposed the following approach:
#[cfg_attr(test, faux::create)]
#[derive(Constructor)]
// when in test, make the `impl` block generated by `derive_more::Constructor` forward a custom attribute
#[cfg_attr(test, constructor(forward = "faux::methods"))]
struct Foo {
bar: Bar,
}
Can you clarify what code this would generate if the test feature is enabled?
Is this request similar to this one? https://github.com/JelteF/derive_more/issues/102
Basically, we would have something like this as a result:
#[cfg_attr(test, faux::methods)]
impl Foo {
fn new(bar: Bar) -> Self {
Self { bar }
}
}
Okay, so if I understand correctly, you want to put an attribute on the generated impl. That does seem useful. forward really isn't the right name though, because that already has a different meaning within derive_more. Something like attr seems a better choice for the name. Feel free to create a PR that implements this.