@@ -279,7 +279,7 @@ where
279279 ///
280280 /// The argument must not have set bits at positions not corresponding to
281281 /// any flag.
282- pub unsafe fn new ( val : T :: Numeric ) -> Self {
282+ pub unsafe fn from_bits_unchecked ( val : T :: Numeric ) -> Self {
283283 BitFlags { val }
284284 }
285285
@@ -307,7 +307,7 @@ where
307307 /// assert_eq!(empty.contains(MyFlag::Three), false);
308308 /// ```
309309 pub fn empty ( ) -> Self {
310- unsafe { BitFlags :: new ( T :: Numeric :: default ( ) ) }
310+ unsafe { BitFlags :: from_bits_unchecked ( T :: Numeric :: default ( ) ) }
311311 }
312312
313313 /// Create a `BitFlags` with all flags set.
@@ -334,7 +334,7 @@ where
334334 /// assert_eq!(empty.contains(MyFlag::Three), true);
335335 /// ```
336336 pub fn all ( ) -> Self {
337- unsafe { BitFlags :: new ( T :: ALL_BITS ) }
337+ unsafe { BitFlags :: from_bits_unchecked ( T :: ALL_BITS ) }
338338 }
339339
340340 /// An empty `BitFlags`. Equivalent to [`empty()`],
@@ -391,12 +391,12 @@ where
391391
392392 /// Turn a `T` into a `BitFlags<T>`. Also available as `flag.into()`.
393393 pub fn from_flag ( flag : T ) -> Self {
394- BitFlags { val : flag. bits ( ) }
394+ unsafe { Self :: from_bits_unchecked ( flag. bits ( ) ) }
395395 }
396396
397397 /// Truncates flags that are illegal
398398 pub fn from_bits_truncate ( bits : T :: Numeric ) -> Self {
399- unsafe { BitFlags :: new ( bits & T :: ALL_BITS ) }
399+ unsafe { BitFlags :: from_bits_unchecked ( bits & T :: ALL_BITS ) }
400400 }
401401
402402 /// Toggles the matching bits
@@ -437,7 +437,7 @@ where
437437{
438438 type Output = BitFlags < T > ;
439439 fn bitor ( self , other : B ) -> BitFlags < T > {
440- unsafe { BitFlags :: new ( self . bits ( ) | other. into ( ) . bits ( ) ) }
440+ unsafe { BitFlags :: from_bits_unchecked ( self . bits ( ) | other. into ( ) . bits ( ) ) }
441441 }
442442}
443443
@@ -448,7 +448,7 @@ where
448448{
449449 type Output = BitFlags < T > ;
450450 fn bitand ( self , other : B ) -> BitFlags < T > {
451- unsafe { BitFlags :: new ( self . bits ( ) & other. into ( ) . bits ( ) ) }
451+ unsafe { BitFlags :: from_bits_unchecked ( self . bits ( ) & other. into ( ) . bits ( ) ) }
452452 }
453453}
454454
@@ -459,7 +459,7 @@ where
459459{
460460 type Output = BitFlags < T > ;
461461 fn bitxor ( self , other : B ) -> BitFlags < T > {
462- unsafe { BitFlags :: new ( self . bits ( ) ^ other. into ( ) . bits ( ) ) }
462+ unsafe { BitFlags :: from_bits_unchecked ( self . bits ( ) ^ other. into ( ) . bits ( ) ) }
463463 }
464464}
465465
@@ -498,7 +498,7 @@ where
498498{
499499 type Output = BitFlags < T > ;
500500 fn not ( self ) -> BitFlags < T > {
501- unsafe { BitFlags :: new ( !self . bits ( ) & T :: ALL_BITS ) }
501+ unsafe { BitFlags :: from_bits_unchecked ( !self . bits ( ) & T :: ALL_BITS ) }
502502 }
503503}
504504
0 commit comments