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

Add FromAttributes trait #151

Closed
TedDriggs opened this issue Nov 12, 2021 · 0 comments
Closed

Add FromAttributes trait #151

TedDriggs opened this issue Nov 12, 2021 · 0 comments

Comments

@TedDriggs
Copy link
Owner

With trait declarations and impl blocks now supporting proc macros, there are too many items for darling to expose dedicated traits and derive macros for each one.

Requirements

  • Easily specify macro ident/path for attribute filtering
  • Merge fields across attribute declarations

Proposed API

pub trait FromAttributes: Sized {
    fn from_attributes(attrs: &[syn::Attribute]) -> darling::Result<Self>;
}

// in customer macro crate

#[derive(FromAttributes)]
#[darling(attributes(sample))]
pub struct SampleReceiver {
    // fields as usual
}

fn macro(input: TokenStream) -> TokenStream {
    let item_impl: syn::ItemImpl = syn::parse_macro_input!(input);
    let root_rec = SampleReceiver::from_attributes(&item_impl);
    // ... elided
}
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

1 participant