mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-13 05:31:02 +00:00
Merge pull request #2338 from serde-rs/atomic
Deduplicate atomic_impl implementations and atomic_impl calls from PR 2337
This commit is contained in:
+18
-42
@@ -2660,10 +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 {
|
macro_rules! atomic_impl {
|
||||||
($($ty:ident)*) => {
|
($($ty:ident $size:expr)*) => {
|
||||||
$(
|
$(
|
||||||
|
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
|
||||||
impl<'de> Deserialize<'de> for $ty {
|
impl<'de> Deserialize<'de> for $ty {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
@@ -2676,50 +2677,25 @@ macro_rules! atomic_impl {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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)]
|
|
||||||
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", no_target_has_atomic, not(no_std_atomic)))]
|
|
||||||
atomic_impl! {
|
atomic_impl! {
|
||||||
AtomicBool
|
AtomicBool "8"
|
||||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
AtomicI8 "8"
|
||||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
AtomicI16 "16"
|
||||||
}
|
AtomicI32 "32"
|
||||||
|
AtomicIsize "ptr"
|
||||||
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
|
AtomicU8 "8"
|
||||||
atomic_impl! {
|
AtomicU16 "16"
|
||||||
AtomicI64 AtomicU64
|
AtomicU32 "32"
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
|
|
||||||
atomic_impl! {
|
|
||||||
AtomicBool "8",
|
|
||||||
AtomicI8 "8",
|
|
||||||
AtomicI16 "16",
|
|
||||||
AtomicI32 "32",
|
|
||||||
AtomicI64 "64",
|
|
||||||
AtomicIsize "ptr",
|
|
||||||
AtomicU8 "8",
|
|
||||||
AtomicU16 "16",
|
|
||||||
AtomicU32 "32",
|
|
||||||
AtomicU64 "64",
|
|
||||||
AtomicUsize "ptr"
|
AtomicUsize "ptr"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "std", not(no_std_atomic64)))]
|
||||||
|
atomic_impl! {
|
||||||
|
AtomicI64 "64"
|
||||||
|
AtomicU64 "64"
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
struct FromStrVisitor<T> {
|
struct FromStrVisitor<T> {
|
||||||
expecting: &'static str,
|
expecting: &'static str,
|
||||||
|
|||||||
+18
-43
@@ -945,10 +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 {
|
macro_rules! atomic_impl {
|
||||||
($($ty:ident)*) => {
|
($($ty:ident $size:expr)*) => {
|
||||||
$(
|
$(
|
||||||
|
#[cfg(any(no_target_has_atomic, target_has_atomic = $size))]
|
||||||
impl Serialize for $ty {
|
impl Serialize for $ty {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
@@ -962,47 +963,21 @@ macro_rules! atomic_impl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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)]
|
|
||||||
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", no_target_has_atomic, not(no_std_atomic)))]
|
|
||||||
atomic_impl! {
|
atomic_impl! {
|
||||||
AtomicBool
|
AtomicBool "8"
|
||||||
AtomicI8 AtomicI16 AtomicI32 AtomicIsize
|
AtomicI8 "8"
|
||||||
AtomicU8 AtomicU16 AtomicU32 AtomicUsize
|
AtomicI16 "16"
|
||||||
}
|
AtomicI32 "32"
|
||||||
|
AtomicIsize "ptr"
|
||||||
#[cfg(all(feature = "std", no_target_has_atomic, not(no_std_atomic64)))]
|
AtomicU8 "8"
|
||||||
atomic_impl! {
|
AtomicU16 "16"
|
||||||
AtomicI64 AtomicU64
|
AtomicU32 "32"
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(no_target_has_atomic)))]
|
|
||||||
atomic_impl! {
|
|
||||||
AtomicBool "8",
|
|
||||||
AtomicI8 "8",
|
|
||||||
AtomicI16 "16",
|
|
||||||
AtomicI32 "32",
|
|
||||||
AtomicI64 "64",
|
|
||||||
AtomicIsize "ptr",
|
|
||||||
AtomicU8 "8",
|
|
||||||
AtomicU16 "16",
|
|
||||||
AtomicU32 "32",
|
|
||||||
AtomicU64 "64",
|
|
||||||
AtomicUsize "ptr"
|
AtomicUsize "ptr"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "std", not(no_std_atomic64)))]
|
||||||
|
atomic_impl! {
|
||||||
|
AtomicI64 "64"
|
||||||
|
AtomicU64 "64"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user