]> git.lizzy.rs Git - enumset.git/commitdiff
Rename from_u128/to_u128 series slightly.
authorLymia Aluysia <lymia@lymiahugs.com>
Sat, 4 Apr 2020 19:45:37 +0000 (12:45 -0700)
committerLymia Aluysia <lymia@lymiahugs.com>
Sat, 4 Apr 2020 19:45:37 +0000 (12:45 -0700)
RELEASES.md
enumset/src/lib.rs
enumset/tests/ops.rs

index 746e66cc986cad22361c1d19567c765e307b744f..25201a87a181621b8a06a83388dca075397018e0 100644 (file)
@@ -1,13 +1,24 @@
 # Version 1.0.0 (2020-04-01) - Unreleased
+
+## Breaking Changes
 * **[WARNING: Potential silent breaking change]** Changed `EnumSet::insert` to
   return whether a value was newly  inserted, rather than whether the value
   already existed in the set. This corresponds better with the behavior of
   `HashSet::insert` and `BTreeSet::insert`.
-* Renamed `to_bits`/`from_bits` to `to_u128`/`from_u128` and added additional
-  methods for other built-in numeric types. 
+* Renamed `to_bits`/`from_bits` to `as_u128`/`from_u128`.
 * `EnumSet::bit_width` and `EnumSet::variant_count` now return a `u32` instead
   of a `u8` for future-proofing.
 * Removed `nightly` feature flag, as it is no longer required.
+
+## New features
+* Added a series of functions like `as_u128`/`from_u128` for other unsigned
+  numeric types. (e.g. `as_u8`/`from_u8`, `as_u16`/`from_u16`, etc)
+* Added variants of `as_u128`/`from_u128` that return an `Option` instead of
+  panicking when the conversion cannot be done.
+* Added variants of `as_u128`/`from_u128` that truncate unknown bits instead
+  of panicking.
+
+## Bugfixes
 * Fixed a bug where the procedural macro would fail on enums with a repr
   annotation set. While reprs larger than u8 are supported, negative enum
   variants or enum variants above 127 are still not currently supported.
index 252f3768452be614b70f38044f5efdd5fa99893f..580debab9f1d4f0d0e43c5482a8bda27ead889c6 100644 (file)
@@ -461,19 +461,18 @@ macro_rules! conversion_impls {
 
 conversion_impls! {
     for_num!(u8, "u8", from_u8, to_u8,
-             from_u8 try_from_u8 from_u8_truncated to_u8 to_u8_checked to_u8_truncated);
+             from_u8 try_from_u8 from_u8_truncated as_u8 try_as_u8 as_u8_truncated);
     for_num!(u16, "u16", from_u16, to_u16,
-             from_u16 try_from_u16 from_u16_truncated to_u16 to_u16_checked to_u16_truncated);
+             from_u16 try_from_u16 from_u16_truncated as_u16 try_as_u16 as_u16_truncated);
     for_num!(u32, "u32", from_u32, to_u32,
-             from_u32 try_from_u32 from_u32_truncated to_u32 to_u32_checked to_u32_truncated);
+             from_u32 try_from_u32 from_u32_truncated as_u32 try_as_u32 as_u32_truncated);
     for_num!(u64, "u64", from_u64, to_u64,
-             from_u64 try_from_u64 from_u64_truncated to_u64 to_u64_checked to_u64_truncated);
+             from_u64 try_from_u64 from_u64_truncated as_u64 try_as_u64 as_u64_truncated);
     for_num!(u128, "u128", from_u128, to_u128,
-             from_u128 try_from_u128 from_u128_truncated to_u128
-             to_u128_checked to_u128_truncated);
+             from_u128 try_from_u128 from_u128_truncated as_u128 try_as_u128 as_u128_truncated);
     for_num!(usize, "usize", from_usize, to_usize,
              from_usize try_from_usize from_usize_truncated
-             to_usize to_usize_checked to_usize_truncated);
+             as_usize try_as_usize as_usize_truncated);
 }
 
 impl <T: EnumSetType> Default for EnumSet<T> {
index fda83d567d1f81c6d55ef9dbcc556b71b40a31b1..aece559ef9748c028d40124c2a58d1a5acde207b 100644 (file)
@@ -236,7 +236,7 @@ macro_rules! test_enum {
         #[test]
         fn to_from_bits() {
             let value = $e::A | $e::C | $e::D | $e::F | $e::E | $e::G;
-            assert_eq!(EnumSet::from_u128(value.to_u128()), value);
+            assert_eq!(EnumSet::from_u128(value.as_u128()), value);
         }
 
         #[test]
@@ -382,12 +382,15 @@ macro_rules! bits_tests {
 }
 
 bits_tests!(test_u8_bits, U8, (U16), u8,
-            to_u8 to_u8_checked to_u8_truncated from_u8 try_from_u8 from_u8_truncated);
+            as_u8 try_as_u8 as_u8_truncated from_u8 try_from_u8 from_u8_truncated);
 bits_tests!(test_u16_bits, U16, (U32), u16,
-            to_u16 to_u16_checked to_u16_truncated from_u16 try_from_u16 from_u16_truncated);
+            as_u16 try_as_u16 as_u16_truncated from_u16 try_from_u16 from_u16_truncated);
 bits_tests!(test_u32_bits, U32, (U64), u32,
-            to_u32 to_u32_checked to_u32_truncated from_u32 try_from_u32 from_u32_truncated);
+            as_u32 try_as_u32 as_u32_truncated from_u32 try_from_u32 from_u32_truncated);
 bits_tests!(test_u64_bits, U64, (U128), u64,
-            to_u64 to_u64_checked to_u64_truncated from_u64 try_from_u64 from_u64_truncated);
+            as_u64 try_as_u64 as_u64_truncated from_u64 try_from_u64 from_u64_truncated);
 bits_tests!(test_u128_bits, U128, (), u128,
-            to_u128 to_u128_checked to_u128_truncated from_u128 try_from_u128 from_u128_truncated);
\ No newline at end of file
+            as_u128 try_as_u128 as_u128_truncated from_u128 try_from_u128 from_u128_truncated);
+bits_tests!(test_uize_bits, U32, (U128), usize,
+            as_usize try_as_usize as_usize_truncated
+            from_usize try_from_usize from_usize_truncated);
\ No newline at end of file