From bcec168e236728a9a9b7d702ced93e565190f675 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 16 Jul 2019 07:36:16 -0700 Subject: [PATCH] Centralize atomic imports --- serde/src/de/impls.rs | 27 ++++++++++++--------------- serde/src/lib.rs | 6 ++++++ serde/src/ser/impls.rs | 29 +++++++++++++---------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/serde/src/de/impls.rs b/serde/src/de/impls.rs index 2ad768a6..494c8a5b 100644 --- a/serde/src/de/impls.rs +++ b/serde/src/de/impls.rs @@ -2546,12 +2546,9 @@ where } } -#[cfg(all(feature = "std", std_integer_atomics))] -use std::sync::atomic; - #[cfg(all(feature = "std", std_integer_atomics))] macro_rules! atomic_impl { - ($ty:path, $primitive:ident) => { + ($ty:ident, $primitive:ident) => { impl<'de> Deserialize<'de> for $ty { #[inline] fn deserialize(deserializer: D) -> Result @@ -2566,34 +2563,34 @@ macro_rules! atomic_impl { } #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicBool, bool); +atomic_impl!(AtomicBool, bool); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI8, i8); +atomic_impl!(AtomicI8, i8); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI16, i16); +atomic_impl!(AtomicI16, i16); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI32, i32); +atomic_impl!(AtomicI32, i32); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI64, i64); +atomic_impl!(AtomicI64, i64); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicIsize, isize); +atomic_impl!(AtomicIsize, isize); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU8, u8); +atomic_impl!(AtomicU8, u8); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU16, u16); +atomic_impl!(AtomicU16, u16); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU32, u32); +atomic_impl!(AtomicU32, u32); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU64, u64); +atomic_impl!(AtomicU64, u64); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicUsize, usize); +atomic_impl!(AtomicUsize, usize); diff --git a/serde/src/lib.rs b/serde/src/lib.rs index 1aba1db8..e4834fd7 100644 --- a/serde/src/lib.rs +++ b/serde/src/lib.rs @@ -212,6 +212,12 @@ mod lib { #[cfg(range_inclusive)] pub use self::core::ops::RangeInclusive; + #[cfg(all(feature = "std", std_integer_atomics))] + pub use std::sync::atomic::{ + AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, + AtomicU64, AtomicU8, AtomicUsize, Ordering, + }; + #[cfg(any(core_duration, feature = "std"))] pub use self::core::time::Duration; } diff --git a/serde/src/ser/impls.rs b/serde/src/ser/impls.rs index 19c6fa8d..c3fccb31 100644 --- a/serde/src/ser/impls.rs +++ b/serde/src/ser/impls.rs @@ -842,53 +842,50 @@ where //////////////////////////////////////////////////////////////////////////////// -#[cfg(all(feature = "std", std_integer_atomics))] -use std::sync::atomic; - #[cfg(all(feature = "std", std_integer_atomics))] macro_rules! atomic_impl { - ($ty:path, $method:ident $($cast:tt)*) => { + ($ty:ident, $method:ident $($cast:tt)*) => { impl Serialize for $ty { #[inline] fn serialize(&self, serializer: S) -> Result where S: Serializer, { - serializer.$method(self.load(atomic::Ordering::SeqCst) $($cast)*) + serializer.$method(self.load(Ordering::SeqCst) $($cast)*) } } } } #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicBool, serialize_bool); +atomic_impl!(AtomicBool, serialize_bool); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI8, serialize_i8); +atomic_impl!(AtomicI8, serialize_i8); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI16, serialize_i16); +atomic_impl!(AtomicI16, serialize_i16); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI32, serialize_i32); +atomic_impl!(AtomicI32, serialize_i32); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicI64, serialize_i64); +atomic_impl!(AtomicI64, serialize_i64); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicIsize, serialize_i64 as i64); +atomic_impl!(AtomicIsize, serialize_i64 as i64); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU8, serialize_u8); +atomic_impl!(AtomicU8, serialize_u8); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU16, serialize_u16); +atomic_impl!(AtomicU16, serialize_u16); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU32, serialize_u32); +atomic_impl!(AtomicU32, serialize_u32); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicU64, serialize_u64); +atomic_impl!(AtomicU64, serialize_u64); #[cfg(all(feature = "std", std_integer_atomics))] -atomic_impl!(atomic::AtomicUsize, serialize_u64 as u64); +atomic_impl!(AtomicUsize, serialize_u64 as u64);