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 conditionally compiled attributes (using #[cfg(...)]) #182

Open
Oliboy50 opened this issue Feb 16, 2024 · 1 comment
Open

Support conditionally compiled attributes (using #[cfg(...)]) #182

Oliboy50 opened this issue Feb 16, 2024 · 1 comment

Comments

@Oliboy50
Copy link
Contributor

Oliboy50 commented Feb 16, 2024

Would it be possible to support feature flipped attributes in the builder arguments such as:

pub struct MyStruct {
    attr1: String,
    attr2: String,
    #[cfg(feature = "my-feature")]
    attr3: String,
}

#[buildstructor::buildstructor]
impl MyStruct {
    #[builder]
    fn new(
        attr1: String, 
        attr2: String, 
        #[cfg(feature = "my-feature")] attr3: String,
    ) -> MyStruct {
        Self { 
            attr1, 
            attr2, 
            #[cfg(feature = "my-feature")] attr3,
        }
    }
}

Right now, I'm sad that this does not compile.

Whereas, if I remove the #[buildstructor::buildstructor] and #[builder] attributes, this compile fine.

You can test it yourself here: https://www.rustexplorer.com/b/ph7z4h

Do you think that it would be possible for the buildstructor proc macro to support this?

Note: It seems to work fine using the #[derive(Builder)] macro: https://www.rustexplorer.com/b/4yi2tr (but I don't use it myself).

@Oliboy50 Oliboy50 changed the title Support conditionally compiled attributes (using #[cfg(...)]) without the derive macro Conditionally compiled attributes (using #[cfg(...)]) without derive macro Feb 16, 2024
@Oliboy50 Oliboy50 changed the title Conditionally compiled attributes (using #[cfg(...)]) without derive macro Support conditionally compiled attributes (using #[cfg(...)]) Feb 16, 2024
@BrynCooke
Copy link
Owner

In theory possible.
At some point I need to get around to updating this crate to use syn2. This will remove a ton of code. But it's probably not on my immediate list of things to do.

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

No branches or pull requests

2 participants