diff options
author | Jingkui Wang <jkwang@google.com> | 2019-03-18 11:22:32 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-03-28 11:17:29 -0700 |
commit | ca224cd547568623dc2479c8cfaca43b091c7650 (patch) | |
tree | bc1ec18e46c53558552e0beb026f0f963c28fb28 /bit_field/src | |
parent | 96e26c2681ee73b6a1e1d2d99aa53a1d21fa494b (diff) | |
download | crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.tar crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.tar.gz crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.tar.bz2 crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.tar.lz crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.tar.xz crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.tar.zst crosvm-ca224cd547568623dc2479c8cfaca43b091c7650.zip |
Change default field type to setter/getter types and remove generated
tests Setter/Getter types will allow better enum fields. Generated tests should be tests for bit_field cargo rather than the defined bit_field struct. BUG=None TEST=cargo test Change-Id: Ib3594e35e28fc393d49c476c9c83fc632cac3190 Reviewed-on: https://chromium-review.googlesource.com/1530454 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Jingkui Wang <jkwang@google.com> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
Diffstat (limited to 'bit_field/src')
-rw-r--r-- | bit_field/src/lib.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/bit_field/src/lib.rs b/bit_field/src/lib.rs index 26e1f36..cafee38 100644 --- a/bit_field/src/lib.rs +++ b/bit_field/src/lib.rs @@ -245,14 +245,17 @@ pub use bit_field_derive::bitfield; pub trait BitFieldSpecifier { // Width of this field in bits. const FIELD_WIDTH: u8; - // Default data type of this field. + // Date type for setter of this field. // For any field, we use the closest u* type. e.g. FIELD_WIDTH <= 8 will // have defulat type of u8. // It's possible to write a custom specifier and use i8. - type DefaultFieldType; + type SetterType; + // Data type for getter of this field. For enums, it will be Result<EnumType, SetterType>. + // For others, it will be the same as SetterType. + type GetterType; - fn from_u64(val: u64) -> Self::DefaultFieldType; - fn into_u64(val: Self::DefaultFieldType) -> u64; + fn from_u64(val: u64) -> Self::GetterType; + fn into_u64(val: Self::SetterType) -> u64; } // Largest u64 representable by this bit field specifier. Used by generated code @@ -272,15 +275,16 @@ bit_field_derive::define_bit_field_specifiers!(); impl BitFieldSpecifier for bool { const FIELD_WIDTH: u8 = 1; - type DefaultFieldType = bool; + type SetterType = bool; + type GetterType = bool; #[inline] - fn from_u64(val: u64) -> Self::DefaultFieldType { + fn from_u64(val: u64) -> Self::GetterType { val > 0 } #[inline] - fn into_u64(val: Self::DefaultFieldType) -> u64 { + fn into_u64(val: Self::SetterType) -> u64 { val as u64 } } |