-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
FromForm flatten attribute #1916
Comments
Yeah, this (among others) is something that the derive simply doesn't do at the moment. Implementing it should be fairly straightforward and in fact is what we already do to handle queries. I'd be happy to review a PR implementing this. As an aside: |
When using
derive
, it is often useful to be able to make common structs that contain fields where everything can be done automatically, and then surrounding structs where only some of the things are derived.To do this, one needs to indicate to each derive macro that the fields of a contained struct should be imported without another level of nesting.
#[serde(flatten)]
,#[row(flatten)]
. But unfortunately there is not a#[field(flatten)]
.For example, I have this in a work-in-progress webapp:
This doesn't work because the generated code expects form submissions containing
common.email
but the actual form contains onlyemail
.Alternatives Considered
Letting the fields be nested the way
FromForm
wants doesn't really work, because whether a field ends up incommon
depends not on anything principled about the system, but simply on whether the automatic handling produced by the derive macros is appropriate.For now I have to just give up on making this part of my code common, and writing some boilerplate to copy fields from one struct to another.
Additional Context
I'm not convinced that
field
is a good name for this attribute. Derive macro inert attributes are in a global namespace. I suggest thatform
would be better. However, it is perhaps too late to change this now.The text was updated successfully, but these errors were encountered: