-
Notifications
You must be signed in to change notification settings - Fork 111
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
derive FromRow
for structs with unnamed fields
#985
derive FromRow
for structs with unnamed fields
#985
Conversation
|
6fb375b
to
1826e69
Compare
I thought that deserialization refactor will make this macro obsolete and later (before 1.0) we're going to remove it. What is the point of spending time on improvements to this macro? |
That's a valid point. Once we have this PR ready, though, it's probably worthy to include it in the next release. 1.0 isn't going to be released very soon, so let's give users this enhancement as early as we can. |
The docstring associated to this function was not easy to understand - it got adjusted. Extracted error message creation to closure, to not repeat same multiple lines of code.
Add a parser util function that extracts the fields from a struct.
This commit prepares for code generation for unnamed fields. The behaviour for named fields becomes unchanged, however code generation logic was slightly adjusted so the very similar approach can be applied to unnamed fields.
This commit adjusts the `from_row_derive` macro function that implements `FromRow` for the structs, so that it works for structs with unnamed fields as well.
1826e69
to
12a0436
Compare
scylla-macros/src/from_row.rs
Outdated
} | ||
}); | ||
crate::parser::StructFields::Unnamed(_fields) => todo!(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The approach here is better for readability that the previous one, but what I had in mind involved adding the Unnamed
variant to the enum only in the next commit, together with the handling logic, so that todo!()
and nonworking-yet-compiled code can be avoided at all.
Fixes: #852
Motivation
For some reason, users were not able to derive
FromRow
trait for structs with unnamed fields.This PR fixes that.
Changes
Adjusted
from_row_derive
function fromscylla-macros
so that it supports structs with unnamed fields as well.Pre-review checklist
./docs/source/
.Fixes:
annotations to PR description.