Skip to content

Commit ca880e3

Browse files
committed
Rename BitFlags::new to from_bits_unchecked.
`new` suggests that this is the main, preferred way of creating `BitFlags`. This is not the case, thus rename it to be consistent with the other from_bits* functions
1 parent ab7ddfe commit ca880e3

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

enumflags_derive/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,23 @@ fn gen_enumflags(ast: &ItemEnum)
228228
type Output = ::enumflags2::BitFlags<#ident>;
229229
fn not(self) -> Self::Output {
230230
use ::enumflags2::{BitFlags, _internal::RawBitFlags};
231-
unsafe { BitFlags::new(self.bits()).not() }
231+
unsafe { BitFlags::from_bits_unchecked(self.bits()).not() }
232232
}
233233
}
234234

235235
impl #std_path::ops::BitOr for #ident {
236236
type Output = ::enumflags2::BitFlags<#ident>;
237237
fn bitor(self, other: Self) -> Self::Output {
238238
use ::enumflags2::{BitFlags, _internal::RawBitFlags};
239-
unsafe { BitFlags::new(self.bits() | other.bits())}
239+
unsafe { BitFlags::from_bits_unchecked(self.bits() | other.bits())}
240240
}
241241
}
242242

243243
impl #std_path::ops::BitAnd for #ident {
244244
type Output = ::enumflags2::BitFlags<#ident>;
245245
fn bitand(self, other: Self) -> Self::Output {
246246
use ::enumflags2::{BitFlags, _internal::RawBitFlags};
247-
unsafe { BitFlags::new(self.bits() & other.bits())}
247+
unsafe { BitFlags::from_bits_unchecked(self.bits() & other.bits())}
248248
}
249249
}
250250

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)