-
Notifications
You must be signed in to change notification settings - Fork 124
docs: Add Portability section for TryFromBytes enum usage #1993
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
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. |
src/lib.rs
Outdated
/// # use zerocopy::{TryFromBytes, KnownLayout, IntoBytes, Immutable}; | ||
/// #[derive(Debug, KnownLayout, Immutable, IntoBytes, TryFromBytes)] |
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.
/// # use zerocopy::{TryFromBytes, KnownLayout, IntoBytes, Immutable}; | |
/// #[derive(Debug, KnownLayout, Immutable, IntoBytes, TryFromBytes)] | |
/// # use zerocopy_derive::TryFromBytes; | |
/// #[derive(TryFromBytes)] |
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.
Ohh, I thought it relates to example. sorry for that. I am going to change it.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1993 +/- ##
=======================================
Coverage 89.46% 89.46%
=======================================
Files 16 16
Lines 5838 5838
=======================================
Hits 5223 5223
Misses 615 615 ☔ View full report in Codecov by Sentry. |
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.
Just one last nit! Otherwise LGTM!
src/lib.rs
Outdated
/// # Portability | ||
/// | ||
/// To ensure consistent endianness for enums with multi-byte representations, | ||
/// explicitly specify and convert each discriminant: | ||
/// | ||
/// Here, `DataStoreVersion` enforces little-endian encoding for each `u32` | ||
/// discriminant, ensuring portability across platforms with differing native endianness. | ||
/// | ||
/// ``` | ||
/// # use zerocopy_derive::TryFromBytes; | ||
/// #[derive(TryFromBytes)] | ||
/// #[repr(u32)] | ||
/// pub enum DataStoreVersion { | ||
/// /// Version 1 of the data store. | ||
/// V1 = 9u32.to_le(), | ||
/// | ||
/// /// Version 2 of the data store. | ||
/// V2 = 10u32.to_le(), | ||
/// } | ||
/// ``` | ||
/// |
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.
Tightening up the prose a bit:
/// # Portability | |
/// | |
/// To ensure consistent endianness for enums with multi-byte representations, | |
/// explicitly specify and convert each discriminant: | |
/// | |
/// Here, `DataStoreVersion` enforces little-endian encoding for each `u32` | |
/// discriminant, ensuring portability across platforms with differing native endianness. | |
/// | |
/// ``` | |
/// # use zerocopy_derive::TryFromBytes; | |
/// #[derive(TryFromBytes)] | |
/// #[repr(u32)] | |
/// pub enum DataStoreVersion { | |
/// /// Version 1 of the data store. | |
/// V1 = 9u32.to_le(), | |
/// | |
/// /// Version 2 of the data store. | |
/// V2 = 10u32.to_le(), | |
/// } | |
/// ``` | |
/// | |
/// # Portability | |
/// | |
/// To ensure consistent endianness for enums with multi-byte representations, | |
/// explicitly specify and convert each discriminant using `.to_le()` or | |
/// `.to_be()`; e.g.: | |
/// | |
/// ``` | |
/// # use zerocopy_derive::TryFromBytes; | |
/// // `DataStoreVersion` is encoded in little-endian. | |
/// #[derive(TryFromBytes)] | |
/// #[repr(u32)] | |
/// pub enum DataStoreVersion { | |
/// /// Version 1 of the data store. | |
/// V1 = 9u32.to_le(), | |
/// | |
/// /// Version 2 of the data store. | |
/// V2 = 10u32.to_le(), | |
/// } | |
/// ``` | |
/// |
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.
Changes done
Backporting in #2390 |
closes #1778