Skip to content

Commit 4c3fcc1

Browse files
committed
WIP
1 parent a098a77 commit 4c3fcc1

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/const_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
pub const CONST_TOKEN: ConstToken<T, T::Numeric> = ConstToken(Self::ALL);
3535
}
3636

37-
for_each_uint! { $ty $hide_docs =>
37+
for_each_uint! { $ty $atomic $hide_docs =>
3838
impl<T> BitFlags<T, $ty> {
3939
/// Create a new BitFlags unsafely, without checking if the bits form
4040
/// a valid bit pattern for the type.

src/fallible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::fmt;
55

66
// Coherence doesn't let us use a generic type here. Work around by implementing
77
// for each integer type manually.
8-
for_each_uint! { $ty $hide_docs =>
8+
for_each_uint! { $ty $atomic $hide_docs =>
99
impl<T> TryFrom<$ty> for BitFlags<T>
1010
where
1111
T: BitFlag<Numeric=$ty>,

src/lib.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,18 @@ pub use enumflags2_derive::bitflags_internal as bitflags;
112112

113113
// Internal macro: expand into a separate copy for each supported numeric type.
114114
macro_rules! for_each_uint {
115-
( $d:tt $tyvar:ident $dd:tt $docattr:ident => $($input:tt)* ) => {
115+
( $d:tt $tyvar:ident $dd:tt $atomic:ident $ddd:tt $docattr:ident => $($input:tt)* ) => {
116116
macro_rules! implement {
117-
( $d $tyvar:ty => $d($d $docattr:meta)? ) => {
117+
( $d $tyvar:ty, $d $atomic:ident => $d($d $docattr:meta)? ) => {
118118
$($input)*
119119
}
120120
}
121121

122-
implement! { u8 => }
123-
implement! { u16 => doc(hidden) }
124-
implement! { u32 => doc(hidden) }
125-
implement! { u64 => doc(hidden) }
126-
implement! { u128 => doc(hidden) }
122+
implement! { u8, AtomicU8 => }
123+
implement! { u16, AtomicU16 => doc(hidden) }
124+
implement! { u32, AtomicU32 => doc(hidden) }
125+
implement! { u64, AtomicU64 => doc(hidden) }
126+
implement! { u128, AtomicU128 => doc(hidden) }
127127
}
128128
}
129129

@@ -334,8 +334,9 @@ pub mod _internal {
334334
}
335335

336336
use ::core::fmt;
337-
use ::core::ops::{BitAnd, BitOr, BitXor, Not, Sub};
338337
use ::core::hash::Hash;
338+
use ::core::ops::{BitAnd, BitOr, BitXor, Not, Sub};
339+
use ::core::sync::atomic;
339340

340341
pub trait BitFlagNum:
341342
Default
@@ -353,15 +354,17 @@ pub mod _internal {
353354
+ Clone
354355
{
355356
const ONE: Self;
357+
type Atomic;
356358

357359
fn is_power_of_two(self) -> bool;
358360
fn count_ones(self) -> u32;
359361
fn wrapping_neg(self) -> Self;
360362
}
361363

362-
for_each_uint! { $ty $hide_docs =>
364+
for_each_uint! { $ty $atomic $hide_docs =>
363365
impl BitFlagNum for $ty {
364366
const ONE: Self = 1;
367+
type Atomic = atomic::$atomic;
365368

366369
fn is_power_of_two(self) -> bool {
367370
<$ty>::is_power_of_two(self)

0 commit comments

Comments
 (0)