-
Notifications
You must be signed in to change notification settings - Fork 138
Introduce HasField trait
#2842
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
Introduce HasField trait
#2842
Conversation
Summary of ChangesHello @jswrenn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a foundational Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces the HasField trait, which allows compile-time reflection on struct fields. The implementation includes a new derive macro for HasField and a compile-time hashing function for field identifiers. The changes are well-structured, but I found a bug in the ToTokens implementation for the Trait enum that will cause compilation failures for existing derives. My review includes a suggestion to fix this.
9526d5d to
2b6d45e
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2842 +/- ##
==========================================
- Coverage 92.33% 92.05% -0.29%
==========================================
Files 20 20
Lines 5794 5812 +18
==========================================
Hits 5350 5350
- Misses 444 462 +18 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2b6d45e to
e5dae4c
Compare
e738a09 to
bced22a
Compare
bced22a to
d8e3bf8
Compare
The `HasField` trait permits privacy-preserving field projections from structs, enums and unions. `HasField` preserves privacy by leveraging the [scoped trait pattern]; for each field `f`, `HasField` is implemented with the `Field` parameter set to a type with identical visibility as `f`. In many useful contexts, this `Field` parameter is inferable, and need not be actually reachable. Consequently, `HasField` can be used to index a field from only the name of a field. See `zerocopy-derive/tests/ui-nightly/privacy.rs` for examples. [scoped trait pattern]: https://jack.wrenn.fyi/blog/private-trait-impls/ gherrit-pr-id: G2238bc341570838db412d880017b3f0c25ac09fa
d8e3bf8 to
bce4eeb
Compare
The
HasFieldtrait permits privacy-preserving field projectionsfrom structs, enums and unions.
HasFieldpreserves privacy by leveraging the scoped trait pattern;for each field
f,HasFieldis implemented with theFieldparameterset to a type with identical visibility as
f. In many useful contexts,this
Fieldparameter is inferable, and need not be actually reachable.Consequently,
HasFieldcan be used to index a field from only the nameof a field. See
zerocopy-derive/tests/ui-nightly/privacy.rsforexamples.
HasField::project; simplifyis_bit_valid#2843HasFieldtrait #2842Latest Update: v2 — Compare vs v1
📚 Full Patch History
Links show the diff between the row version and the column version.