From 85ae57040d4d4818932445a83274deaff4cd7c7b Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 16 Jul 2019 07:46:44 -0700 Subject: [PATCH] One macro to deserialize all atomics --- serde/src/de/impls.rs | 55 ++++++++++++------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 1431fa42..66825b1f 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2548,48 +2548,23 @@ where #[cfg(all(feature = "std", std_integer_atomics))] macro_rules! atomic_impl { - ($ty:ident) => { - impl<'de> Deserialize<'de> for $ty { - #[inline] - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - Deserialize::deserialize(deserializer).map(Self::new) + ($($ty:ident)*) => { + $( + impl<'de> Deserialize<'de> for $ty { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + Deserialize::deserialize(deserializer).map(Self::new) + } } - } + )* }; } #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicBool); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicI8); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicI16); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicI32); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicI64); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicIsize); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicU8); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicU16); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicU32); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicU64); - -#[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(AtomicUsize); +atomic_impl! { + AtomicBool + AtomicI8 AtomicI16 AtomicI32 AtomicI64 AtomicIsize + AtomicU8 AtomicU16 AtomicU32 AtomicU64 AtomicUsize +}