| 1 |
use crate::{de::Decode, enc::Encode, impl_borrow_decode}; |
| 2 |
use core::sync::atomic::Ordering; |
| 3 |
|
| 4 |
#[cfg(target_has_atomic = "ptr")] |
| 5 |
use core::sync::atomic::{AtomicIsize, AtomicUsize}; |
| 6 |
|
| 7 |
#[cfg(target_has_atomic = "8")] |
| 8 |
use core::sync::atomic::{AtomicBool, AtomicI8, AtomicU8}; |
| 9 |
|
| 10 |
#[cfg(target_has_atomic = "16")] |
| 11 |
use core::sync::atomic::{AtomicI16, AtomicU16}; |
| 12 |
|
| 13 |
#[cfg(target_has_atomic = "32")] |
| 14 |
use core::sync::atomic::{AtomicI32, AtomicU32}; |
| 15 |
|
| 16 |
#[cfg(target_has_atomic = "64")] |
| 17 |
use core::sync::atomic::{AtomicI64, AtomicU64}; |
| 18 |
|
| 19 |
#[cfg(target_has_atomic = "8")] |
| 20 |
impl Encode for AtomicBool { |
| 21 |
fn encode<E: crate::enc::Encoder>( |
| 22 |
&self, |
| 23 |
encoder: &mut E, |
| 24 |
) -> Result<(), crate::error::EncodeError> { |
| 25 |
self.load(Ordering::SeqCst).encode(encoder) |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
#[cfg(target_has_atomic = "8")] |
| 30 |
impl<Context> Decode<Context> for AtomicBool { |
| 31 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 32 |
Ok(AtomicBool::new(Decode::decode(decoder)?)) |
| 33 |
} |
| 34 |
} |
| 35 |
#[cfg(target_has_atomic = "8")] |
| 36 |
impl_borrow_decode!(AtomicBool); |
| 37 |
|
| 38 |
#[cfg(target_has_atomic = "8")] |
| 39 |
impl Encode for AtomicU8 { |
| 40 |
fn encode<E: crate::enc::Encoder>( |
| 41 |
&self, |
| 42 |
encoder: &mut E, |
| 43 |
) -> Result<(), crate::error::EncodeError> { |
| 44 |
self.load(Ordering::SeqCst).encode(encoder) |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
#[cfg(target_has_atomic = "8")] |
| 49 |
impl<Context> Decode<Context> for AtomicU8 { |
| 50 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 51 |
Ok(AtomicU8::new(Decode::decode(decoder)?)) |
| 52 |
} |
| 53 |
} |
| 54 |
#[cfg(target_has_atomic = "8")] |
| 55 |
impl_borrow_decode!(AtomicU8); |
| 56 |
|
| 57 |
#[cfg(target_has_atomic = "16")] |
| 58 |
impl Encode for AtomicU16 { |
| 59 |
fn encode<E: crate::enc::Encoder>( |
| 60 |
&self, |
| 61 |
encoder: &mut E, |
| 62 |
) -> Result<(), crate::error::EncodeError> { |
| 63 |
self.load(Ordering::SeqCst).encode(encoder) |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
#[cfg(target_has_atomic = "16")] |
| 68 |
impl<Context> Decode<Context> for AtomicU16 { |
| 69 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 70 |
Ok(AtomicU16::new(Decode::decode(decoder)?)) |
| 71 |
} |
| 72 |
} |
| 73 |
#[cfg(target_has_atomic = "16")] |
| 74 |
impl_borrow_decode!(AtomicU16); |
| 75 |
|
| 76 |
#[cfg(target_has_atomic = "32")] |
| 77 |
impl Encode for AtomicU32 { |
| 78 |
fn encode<E: crate::enc::Encoder>( |
| 79 |
&self, |
| 80 |
encoder: &mut E, |
| 81 |
) -> Result<(), crate::error::EncodeError> { |
| 82 |
self.load(Ordering::SeqCst).encode(encoder) |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
#[cfg(target_has_atomic = "32")] |
| 87 |
impl<Context> Decode<Context> for AtomicU32 { |
| 88 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 89 |
Ok(AtomicU32::new(Decode::decode(decoder)?)) |
| 90 |
} |
| 91 |
} |
| 92 |
#[cfg(target_has_atomic = "32")] |
| 93 |
impl_borrow_decode!(AtomicU32); |
| 94 |
|
| 95 |
#[cfg(target_has_atomic = "64")] |
| 96 |
impl Encode for AtomicU64 { |
| 97 |
fn encode<E: crate::enc::Encoder>( |
| 98 |
&self, |
| 99 |
encoder: &mut E, |
| 100 |
) -> Result<(), crate::error::EncodeError> { |
| 101 |
self.load(Ordering::SeqCst).encode(encoder) |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
#[cfg(target_has_atomic = "64")] |
| 106 |
impl<Context> Decode<Context> for AtomicU64 { |
| 107 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 108 |
Ok(AtomicU64::new(Decode::decode(decoder)?)) |
| 109 |
} |
| 110 |
} |
| 111 |
#[cfg(target_has_atomic = "64")] |
| 112 |
impl_borrow_decode!(AtomicU64); |
| 113 |
|
| 114 |
#[cfg(target_has_atomic = "ptr")] |
| 115 |
impl Encode for AtomicUsize { |
| 116 |
fn encode<E: crate::enc::Encoder>( |
| 117 |
&self, |
| 118 |
encoder: &mut E, |
| 119 |
) -> Result<(), crate::error::EncodeError> { |
| 120 |
self.load(Ordering::SeqCst).encode(encoder) |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
#[cfg(target_has_atomic = "ptr")] |
| 125 |
impl<Context> Decode<Context> for AtomicUsize { |
| 126 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 127 |
Ok(AtomicUsize::new(Decode::decode(decoder)?)) |
| 128 |
} |
| 129 |
} |
| 130 |
#[cfg(target_has_atomic = "ptr")] |
| 131 |
impl_borrow_decode!(AtomicUsize); |
| 132 |
|
| 133 |
#[cfg(target_has_atomic = "8")] |
| 134 |
impl Encode for AtomicI8 { |
| 135 |
fn encode<E: crate::enc::Encoder>( |
| 136 |
&self, |
| 137 |
encoder: &mut E, |
| 138 |
) -> Result<(), crate::error::EncodeError> { |
| 139 |
self.load(Ordering::SeqCst).encode(encoder) |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
#[cfg(target_has_atomic = "8")] |
| 144 |
impl<Context> Decode<Context> for AtomicI8 { |
| 145 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 146 |
Ok(AtomicI8::new(Decode::decode(decoder)?)) |
| 147 |
} |
| 148 |
} |
| 149 |
#[cfg(target_has_atomic = "8")] |
| 150 |
impl_borrow_decode!(AtomicI8); |
| 151 |
|
| 152 |
#[cfg(target_has_atomic = "16")] |
| 153 |
impl Encode for AtomicI16 { |
| 154 |
fn encode<E: crate::enc::Encoder>( |
| 155 |
&self, |
| 156 |
encoder: &mut E, |
| 157 |
) -> Result<(), crate::error::EncodeError> { |
| 158 |
self.load(Ordering::SeqCst).encode(encoder) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
#[cfg(target_has_atomic = "16")] |
| 163 |
impl<Context> Decode<Context> for AtomicI16 { |
| 164 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 165 |
Ok(AtomicI16::new(Decode::decode(decoder)?)) |
| 166 |
} |
| 167 |
} |
| 168 |
#[cfg(target_has_atomic = "16")] |
| 169 |
impl_borrow_decode!(AtomicI16); |
| 170 |
|
| 171 |
#[cfg(target_has_atomic = "32")] |
| 172 |
impl Encode for AtomicI32 { |
| 173 |
fn encode<E: crate::enc::Encoder>( |
| 174 |
&self, |
| 175 |
encoder: &mut E, |
| 176 |
) -> Result<(), crate::error::EncodeError> { |
| 177 |
self.load(Ordering::SeqCst).encode(encoder) |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
#[cfg(target_has_atomic = "32")] |
| 182 |
impl<Context> Decode<Context> for AtomicI32 { |
| 183 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 184 |
Ok(AtomicI32::new(Decode::decode(decoder)?)) |
| 185 |
} |
| 186 |
} |
| 187 |
#[cfg(target_has_atomic = "32")] |
| 188 |
impl_borrow_decode!(AtomicI32); |
| 189 |
|
| 190 |
#[cfg(target_has_atomic = "64")] |
| 191 |
impl Encode for AtomicI64 { |
| 192 |
fn encode<E: crate::enc::Encoder>( |
| 193 |
&self, |
| 194 |
encoder: &mut E, |
| 195 |
) -> Result<(), crate::error::EncodeError> { |
| 196 |
self.load(Ordering::SeqCst).encode(encoder) |
| 197 |
} |
| 198 |
} |
| 199 |
|
| 200 |
#[cfg(target_has_atomic = "64")] |
| 201 |
impl<Context> Decode<Context> for AtomicI64 { |
| 202 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 203 |
Ok(AtomicI64::new(Decode::decode(decoder)?)) |
| 204 |
} |
| 205 |
} |
| 206 |
#[cfg(target_has_atomic = "64")] |
| 207 |
impl_borrow_decode!(AtomicI64); |
| 208 |
|
| 209 |
#[cfg(target_has_atomic = "ptr")] |
| 210 |
impl Encode for AtomicIsize { |
| 211 |
fn encode<E: crate::enc::Encoder>( |
| 212 |
&self, |
| 213 |
encoder: &mut E, |
| 214 |
) -> Result<(), crate::error::EncodeError> { |
| 215 |
self.load(Ordering::SeqCst).encode(encoder) |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
#[cfg(target_has_atomic = "ptr")] |
| 220 |
impl<Context> Decode<Context> for AtomicIsize { |
| 221 |
fn decode<D: crate::de::Decoder>(decoder: &mut D) -> Result<Self, crate::error::DecodeError> { |
| 222 |
Ok(AtomicIsize::new(Decode::decode(decoder)?)) |
| 223 |
} |
| 224 |
} |
| 225 |
#[cfg(target_has_atomic = "ptr")] |
| 226 |
impl_borrow_decode!(AtomicIsize); |