Skip to content

Commit 7440e56

Browse files
committed
Deduplicate atomic_impl macro implementations
1 parent 0d79306 commit 7440e56

2 files changed

Lines changed: 4 additions & 37 deletions

File tree

‎serde/src/de/impls.rs‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2660,27 +2660,11 @@ where
26602660
}
26612661
}
26622662

2663-
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
2664-
macro_rules! atomic_impl {
2665-
($($ty:ident $size:expr)*) => {
2666-
$(
2667-
impl<'de> Deserialize<'de> for $ty {
2668-
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2669-
where
2670-
D: Deserializer<'de>,
2671-
{
2672-
Deserialize::deserialize(deserializer).map(Self::new)
2673-
}
2674-
}
2675-
)*
2676-
};
2677-
}
2678-
2679-
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
2663+
#[cfg(all(feature = "std", not(no_std_atomic)))]
26802664
macro_rules! atomic_impl {
26812665
($($ty:ident $size:expr)*) => {
26822666
$(
2683-
#[cfg(target_has_atomic = $size)]
2667+
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
26842668
impl<'de> Deserialize<'de> for $ty {
26852669
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
26862670
where

‎serde/src/ser/impls.rs‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -945,28 +945,11 @@ where
945945

946946
////////////////////////////////////////////////////////////////////////////////
947947

948-
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic)))]
949-
macro_rules! atomic_impl {
950-
($($ty:ident $size:expr)*) => {
951-
$(
952-
impl Serialize for $ty {
953-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
954-
where
955-
S: Serializer,
956-
{
957-
// Matches the atomic ordering used in libcore for the Debug impl
958-
self.load(Ordering::Relaxed).serialize(serializer)
959-
}
960-
}
961-
)*
962-
}
963-
}
964-
965-
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
948+
#[cfg(all(feature = "std", not(no_std_atomic)))]
966949
macro_rules! atomic_impl {
967950
($($ty:ident $size:expr)*) => {
968951
$(
969-
#[cfg(target_has_atomic = $size)]
952+
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
970953
impl Serialize for $ty {
971954
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
972955
where

0 commit comments

Comments
 (0)