Skip to content

Commit

Permalink
Deduplicate atomic_impl macro implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 12, 2022
1 parent 0d79306 commit 7440e56
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
20 changes: 2 additions & 18 deletions serde/src/de/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2660,27 +2660,11 @@ where
}
}

#[cfg(all(feature = "std", no_target_has_atomic, 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)))]
#[cfg(all(feature = "std", not(no_std_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
Expand Down
21 changes: 2 additions & 19 deletions serde/src/ser/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,28 +945,11 @@ where

////////////////////////////////////////////////////////////////////////////////

#[cfg(all(feature = "std", no_target_has_atomic, 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)))]
#[cfg(all(feature = "std", not(no_std_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
Expand Down

0 comments on commit 7440e56

Please sign in to comment.