Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support adding an arbitrary attribute on top of Constructor impl #336

Open
FalkWoldmann opened this issue Feb 15, 2024 · 3 comments
Open

Comments

@FalkWoldmann
Copy link

Hi,

as discussed in nrxus/faux#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,
}
@JelteF
Copy link
Owner

JelteF commented Mar 15, 2024

Can you clarify what code this would generate if the test feature is enabled?

Is this request similar to this one? #102

@FalkWoldmann
Copy link
Author

Basically, we would have something like this as a result:

#[cfg_attr(test, faux::methods)]
impl Foo {
    fn new(bar: Bar) -> Self {
        Self { bar }
    }
}

@JelteF
Copy link
Owner

JelteF commented Mar 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants