Deduplicate atomic_impl macro implementations

This commit is contained in:
David Tolnay 2022-12-11 16:09:26 -08:00
parent 0d79306285
commit 7440e56c53
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 4 additions and 37 deletions

View File

@ -2660,27 +2660,11 @@ where
}
}
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
#[cfg(all(feature = "std", not(no_std_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
impl<'de> Deserialize<'de> for $ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
Deserialize::deserialize(deserializer).map(Self::new)
}
}
)*
};
}
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
#[cfg(target_has_atomic = $size)]
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
impl<'de> Deserialize<'de> for $ty {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where

View File

@ -945,28 +945,11 @@ where
////////////////////////////////////////////////////////////////////////////////
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
#[cfg(all(feature = "std", not(no_std_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
impl Serialize for $ty {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
// Matches the atomic ordering used in libcore for the Debug impl
self.load(Ordering::Relaxed).serialize(serializer)
}
}
)*
}
}
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
macro_rules! atomic_impl {
($($ty:ident $size:expr)*) => {
$(
#[cfg(target_has_atomic = $size)]
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
impl Serialize for $ty {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where