Centralize atomic imports

This commit is contained in:
David Tolnay 2019-07-16 07:36:16 -07:00
parent 102a332616
commit bcec168e23
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 31 additions and 31 deletions

View File

@ -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<D>(deserializer: D) -> Result<Self, D::Error>
@ -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);

View File

@ -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;
}

View File

@ -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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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);