Skip to content

Commit ab7ddfe

Browse files
committed
Rename RawBitFlags::Type to Numeric.
Type is a very generic, non-descriptive name. Moreover, the name is not a part of the public interface.
1 parent 103a43e commit ab7ddfe

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

enumflags_derive/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,11 @@ fn gen_enumflags(ast: &ItemEnum)
256256
}
257257

258258
impl ::enumflags2::_internal::RawBitFlags for #ident {
259-
type Type = #ty;
259+
type Numeric = #ty;
260260

261-
const EMPTY: Self::Type = 0;
261+
const EMPTY: Self::Numeric = 0;
262262

263-
const ALL_BITS: Self::Type =
263+
const ALL_BITS: Self::Numeric =
264264
0 #(| (#repeated_name::#variant_names as #ty))*;
265265

266266
const FLAG_LIST: &'static [Self] =
@@ -269,7 +269,7 @@ fn gen_enumflags(ast: &ItemEnum)
269269
const BITFLAGS_TYPE_NAME : &'static str =
270270
concat!("BitFlags<", stringify!(#ident), ">");
271271

272-
fn bits(self) -> Self::Type {
272+
fn bits(self) -> Self::Numeric {
273273
self as #ty
274274
}
275275
}

src/fallible.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ macro_rules! impl_try_from {
1010
$(
1111
impl<T> TryFrom<$ty> for BitFlags<T>
1212
where
13-
T: BitFlag<Type=$ty>,
13+
T: BitFlag<Numeric=$ty>,
1414
{
1515
type Error = FromBitsError<T>;
1616

17-
fn try_from(bits: T::Type) -> Result<Self, Self::Error> {
17+
fn try_from(bits: T::Numeric) -> Result<Self, Self::Error> {
1818
Self::from_bits(bits)
1919
}
2020
}
@@ -52,7 +52,7 @@ impl_try_from! {
5252
#[derive(Debug, Copy, Clone)]
5353
pub struct FromBitsError<T: BitFlag> {
5454
pub(crate) flags: BitFlags<T>,
55-
pub(crate) invalid: T::Type,
55+
pub(crate) invalid: T::Numeric,
5656
}
5757

5858
impl<T: BitFlag> FromBitsError<T> {
@@ -62,7 +62,7 @@ impl<T: BitFlag> FromBitsError<T> {
6262
}
6363

6464
/// Return the bits that didn't correspond to any flags.
65-
pub fn invalid_bits(self) -> T::Type {
65+
pub fn invalid_bits(self) -> T::Numeric {
6666
self.invalid
6767
}
6868
}

src/formatting.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
impl<T> fmt::Binary for BitFlags<T>
3939
where
4040
T: BitFlag,
41-
T::Type: fmt::Binary,
41+
T::Numeric: fmt::Binary,
4242
{
4343
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
4444
fmt::Binary::fmt(&self.bits(), fmt)
@@ -48,7 +48,7 @@ where
4848
impl<T> fmt::Octal for BitFlags<T>
4949
where
5050
T: BitFlag,
51-
T::Type: fmt::Octal,
51+
T::Numeric: fmt::Octal,
5252
{
5353
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5454
fmt::Octal::fmt(&self.bits(), fmt)
@@ -58,7 +58,7 @@ where
5858
impl<T> fmt::LowerHex for BitFlags<T>
5959
where
6060
T: BitFlag,
61-
T::Type: fmt::LowerHex,
61+
T::Numeric: fmt::LowerHex,
6262
{
6363
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
6464
fmt::LowerHex::fmt(&self.bits(), fmt)
@@ -68,7 +68,7 @@ where
6868
impl<T> fmt::UpperHex for BitFlags<T>
6969
where
7070
T: BitFlag,
71-
T::Type: fmt::UpperHex,
71+
T::Numeric: fmt::UpperHex,
7272
{
7373
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
7474
fmt::UpperHex::fmt(&self.bits(), fmt)

src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ pub mod _internal {
165165
/// a valid type parameter for `BitFlags<T>`.
166166
pub trait RawBitFlags: Copy + Clone + 'static {
167167
/// The underlying integer type.
168-
type Type: BitFlagNum;
168+
type Numeric: BitFlagNum;
169169

170170
/// A value with no bits set.
171-
const EMPTY: Self::Type;
171+
const EMPTY: Self::Numeric;
172172

173173
/// A value with all flag bits set.
174-
const ALL_BITS: Self::Type;
174+
const ALL_BITS: Self::Numeric;
175175

176176
/// A slice that contains each variant exactly one.
177177
const FLAG_LIST: &'static [Self];
@@ -182,7 +182,7 @@ pub mod _internal {
182182
const BITFLAGS_TYPE_NAME: &'static str;
183183

184184
/// Return the bits as a number type.
185-
fn bits(self) -> Self::Type;
185+
fn bits(self) -> Self::Numeric;
186186
}
187187

188188
use ::core::ops::{BitAnd, BitOr, BitXor, Not};
@@ -238,7 +238,7 @@ pub mod _internal {
238238
// Internal debug formatting implementations
239239
mod formatting;
240240

241-
// impl TryFrom<T::Type> for BitFlags<T>
241+
// impl TryFrom<T::Numeric> for BitFlags<T>
242242
mod fallible;
243243
pub use crate::fallible::FromBitsError;
244244

@@ -247,7 +247,7 @@ pub use crate::fallible::FromBitsError;
247247
#[derive(Copy, Clone, Eq, Hash)]
248248
#[repr(transparent)]
249249
pub struct BitFlags<T: BitFlag> {
250-
val: T::Type,
250+
val: T::Numeric,
251251
}
252252

253253
/// The default value returned is one with all flags unset, i. e. [`empty`][Self::empty].
@@ -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::Type) -> Self {
282+
pub unsafe fn new(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::Type::default()) }
310+
unsafe { BitFlags::new(T::Numeric::default()) }
311311
}
312312

313313
/// Create a `BitFlags` with all flags set.
@@ -360,7 +360,7 @@ where
360360
}
361361

362362
/// Returns the underlying type value
363-
pub fn bits(self) -> T::Type {
363+
pub fn bits(self) -> T::Numeric {
364364
self.val
365365
}
366366

@@ -377,7 +377,7 @@ where
377377

378378
/// Returns a `BitFlags<T>` if the raw value provided does not contain
379379
/// any illegal flags.
380-
pub fn from_bits(bits: T::Type) -> Result<Self, FromBitsError<T>> {
380+
pub fn from_bits(bits: T::Numeric) -> Result<Self, FromBitsError<T>> {
381381
let flags = Self::from_bits_truncate(bits);
382382
if flags.bits() == bits {
383383
Ok(flags)
@@ -395,7 +395,7 @@ where
395395
}
396396

397397
/// Truncates flags that are illegal
398-
pub fn from_bits_truncate(bits: T::Type) -> Self {
398+
pub fn from_bits_truncate(bits: T::Numeric) -> Self {
399399
unsafe { BitFlags::new(bits & T::ALL_BITS) }
400400
}
401401

@@ -537,10 +537,10 @@ mod impl_serde {
537537
impl<'a, T> Deserialize<'a> for BitFlags<T>
538538
where
539539
T: BitFlag,
540-
T::Type: Deserialize<'a> + Into<u64>,
540+
T::Numeric: Deserialize<'a> + Into<u64>,
541541
{
542542
fn deserialize<D: serde::Deserializer<'a>>(d: D) -> Result<Self, D::Error> {
543-
let val = T::Type::deserialize(d)?;
543+
let val = T::Numeric::deserialize(d)?;
544544
Self::from_bits(val)
545545
.map_err(|_| D::Error::invalid_value(
546546
Unexpected::Unsigned(val.into()),
@@ -552,10 +552,10 @@ mod impl_serde {
552552
impl<T> Serialize for BitFlags<T>
553553
where
554554
T: BitFlag,
555-
T::Type: Serialize,
555+
T::Numeric: Serialize,
556556
{
557557
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
558-
T::Type::serialize(&self.val, s)
558+
T::Numeric::serialize(&self.val, s)
559559
}
560560
}
561561
}

0 commit comments

Comments
 (0)