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

Multiple FromAttributes structs with same name? #11

Open
kangalio opened this issue Mar 6, 2022 · 0 comments
Open

Multiple FromAttributes structs with same name? #11

kangalio opened this issue Mar 6, 2022 · 0 comments

Comments

@kangalio
Copy link

kangalio commented Mar 6, 2022

Use case:

#[derive(MyDeriveMacro)]
#[my_derive_macro(/* struct attributes */)]
struct Foo {
    #[my_derive_macro(/* field attributes */)]
    bar: syn::LitIdent,
}

The set of valid attributes on the struct vs on a field is different, but the name my_derive_macro should stay the same. How to achieve this with bae? Is this the best way?:

mod struct_attrs {
    #[derive(bae::FromAttributes)]
    pub struct MyDeriveMacro { /* struct attributes */ }
}
use struct_attrs::MyDeriveMacro as StructAttrs;

mod field_attrs {
    #[derive(bae::FromAttributes)]
    pub struct MyDeriveMacro { /* field attributes */ }
}
use field_attrs::MyDeriveMacro as FieldAttrs;

A #[bae(name = "...")]/#[bae(rename = "...")]/#[bae(prefix = "...")] attribute on FromAttributes-derived structs could solve this nicely:

#[derive(bae::FromAttributes)]
#[bae(name = "my_derive_macro")]
pub struct StructAttrs { /* struct attributes */ }

#[derive(bae::FromAttributes)]
#[bae(name = "my_derive_macro")]
pub struct FieldAttrs { /* field attributes */ }

Would such a PR be accepted?

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

1 participant