-
Notifications
You must be signed in to change notification settings - Fork 68
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 support for flatten
#146
Comments
I don't think this is possible without a fundamental rework of I'm open to proposals on how to implement this, as long as:
|
I have an idea of how to do this in a limited capacity. When If // #[sample(known, known_2 = "...", unknown_1, unknown_2 = "..."))]
#[derive(FromMeta)]
struct A {
known: Flag,
known_2: String,
#[darling(flatten)]
other: B,
}
#[derive(FromMeta)]
struct B {
unknown_1: Flag,
unknown_2: String,
} Pitfalls
Open Questions
|
This could be possible to mitigate by adding a function to |
Suppose we have the following traits:
and we want to provide derive macros for both of them where
#[derive(Foo)]
derives onlyFoo
trait and#[derive(Bar)]
derives bothFoo
andBar
traits (basically#[derive(Bar)]
automatically adds#[derive(Foo)]
without the user needing to write additional derive explicitly.When implementing
#[derive(Bar)]
we would also want to access the field or enum variant attributes that#[derive(Foo)]
requires.With
darling
this isn't very simple to do this for now.As for now we would need to do it like this:
Long example
Instead of this I propose to add
#[darling(flatten)]
attribute that works similar toserde
's analogue.Something like this:
However, there are still open questions about how
#[darling(attributes, supports)]
should behave when flattening and there will also be severalident, attrs
and other data extracted from the parsed field, derive input or enum variant which make flattening feature no so straightforward...The text was updated successfully, but these errors were encountered: