-
Notifications
You must be signed in to change notification settings - Fork 134
Add serde optional feature to serialize primitive types #2815
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
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @ElouanPetereau, 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 enhances the crate by integrating an optional 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
|
139f733 to
d9a6d76
Compare
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 a serde feature to allow serialization and deserialization of the byteorder numeric wrappers, which is a great addition for interoperability. The implementation is clean, adding the Serialize and Deserialize impls within the define_type! macro behind the new feature flag. The accompanying tests are thorough and cover round-trip serialization for all relevant types, including within a struct.
I have a couple of suggestions regarding dependency versions in Cargo.toml to use more recent, but still MSRV-compatible, versions of serde and serde_json.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2815 +/- ##
==========================================
+ Coverage 88.14% 88.26% +0.11%
==========================================
Files 20 20
Lines 5450 5505 +55
==========================================
+ Hits 4804 4859 +55
Misses 646 646 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
e15adae to
1982814
Compare
joshlf
left a comment
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.
Wow, thanks for this! I'm sure others will find this useful too.
I'm broadly on board with the implementation – just a few small changes requested.
src/lib.rs
Outdated
| //! zerocopy_derive::FromBytes`). | ||
| //! | ||
| //! - **`serde`** | ||
| //! Provides `Serialize` and `Deserialize` impls for the `byteorder` numeric |
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.
| //! Provides `Serialize` and `Deserialize` impls for the `byteorder` numeric | |
| //! Provides [`serde`] [`Serialize`] and [`Deserialize`] impls for the [`byteorder`] numeric |
(or something along these lines – just want to mention serde, and want to make things into doc links)
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.
I cannot use the doc links directly as the feature is optional and when it is not used serde is not imported. I guarded this doc part with a config attribute and updated slightly the doc when not using the serde feature to specify that the implemented traits come from serde, wdyt?
Additionally, I fixed the links for the simd feature just below, or rather added the links that where missing:
-//! When the `simd` feature is enabled, `FromZeros`, `FromBytes`, and
-//! `IntoBytes` impls are emitted for all stable SIMD types which exist on the
+//! When the `simd` feature is enabled, [`FromZeros`], [`FromBytes`], and
+//! [`IntoBytes`] impls are emitted for all stable SIMD types which exist on theThere 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.
It seems using the config attribute breaks the readme option of cargo and I did not realize that the README.md and the doc comment need to be a 1:1 match every time so I cannot use a conditional doc anyway.
I switched to add a link to the serde crate repository but I had to update the generate-readme crate because it was removing the square brackets on proper links with urls ([]()) where it should only do it for Rust doc links ([]).
Wdyt?
ddfcc9a to
2db4c01
Compare
2db4c01 to
519fc0c
Compare
This pull request add a feature named
serdeto enable serializing and deserializing thebyteordernumeric wrappers using serde derives.Why
The reason for adding this is that I need to be able to convert a struct to either:
zerocopyon my struct)CSVorjsonwhich doesn't need to be as fast (usingserdeon my struct)Instead of having to manually write the
serde:Serializeandserde:Deserializetraits every time for my structs and calling theget()/from()function to get the inner type, e.g.f64for anF64, it would have been easier to use theSerializeandDeserializederives provided by the serde crate.How
This simply update the
define_type!()macro to add theSerializeandDeserializetrait implementations using theget()/from()function to get the inner type when theserdefeature is enabled.Thank you for your work in maintaining this project.