Skip to content

Commit 8861464

Browse files
committed
Simplify the impl_try_from macro
1 parent e3cf71f commit 8861464

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

enumflags/src/fallible.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,27 @@ use super::BitFlags;
33
use super::_internal::RawBitFlags;
44

55
macro_rules! impl_try_from {
6-
() => { };
7-
($ty:ty, $($tt:tt)*) => {
8-
impl_try_from! { $ty }
9-
impl_try_from! { $($tt)* }
10-
};
11-
($ty:ty) => {
12-
impl<T> TryFrom<$ty> for BitFlags<T>
13-
where
14-
T: RawBitFlags<Type=$ty>,
15-
{
16-
type Error = FromBitsError<T>;
6+
($($ty:ty),*) => {
7+
$(
8+
impl<T> TryFrom<$ty> for BitFlags<T>
9+
where
10+
T: RawBitFlags<Type=$ty>,
11+
{
12+
type Error = FromBitsError<T>;
1713

18-
fn try_from(bits: T::Type) -> Result<Self, Self::Error> {
19-
let flags = Self::from_bits_truncate(bits);
20-
if flags.bits() == bits {
21-
Ok(flags)
22-
} else {
23-
Err(FromBitsError {
24-
flags,
25-
invalid: bits & !flags.bits(),
26-
})
14+
fn try_from(bits: T::Type) -> Result<Self, Self::Error> {
15+
let flags = Self::from_bits_truncate(bits);
16+
if flags.bits() == bits {
17+
Ok(flags)
18+
} else {
19+
Err(FromBitsError {
20+
flags,
21+
invalid: bits & !flags.bits(),
22+
})
23+
}
2724
}
2825
}
29-
}
26+
)*
3027
};
3128
}
3229

0 commit comments

Comments
 (0)