diff --git a/Cargo.toml b/Cargo.toml index c634072..e3f9662 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ atomic_f64 = [] [dependencies] serde = { version = "1", optional = true, default-features = false } +atomic-traits = { version = "0.4", optional = true } [dev-dependencies] serde_test = { version = "1", default-features = false } diff --git a/src/atomic_f32.rs b/src/atomic_f32.rs index be088a6..eeaa44a 100644 --- a/src/atomic_f32.rs +++ b/src/atomic_f32.rs @@ -817,3 +817,60 @@ impl PartialEq for AtomicF32 { self.load(Relaxed) == o.load(Relaxed) } } +#[cfg(feature = "atomic-traits")] +impl atomic_traits::Atomic for AtomicF32 { + type Type = f32; + + fn new(v: Self::Type) -> Self { + Self::new(v) + } + + fn get_mut(&mut self) -> &mut Self::Type { + self.get_mut() + } + + fn into_inner(self) -> Self::Type { + self.into_inner() + } + + fn load(&self, order: Ordering) -> Self::Type { + self.load(order) + } + + fn store(&self, val: Self::Type, order: Ordering) { + self.store(val, order) + } + + fn swap(&self, val: Self::Type, order: Ordering) -> Self::Type { + self.swap(val, order) + } + + fn compare_and_swap( + &self, + current: Self::Type, + new: Self::Type, + order: Ordering, + ) -> Self::Type { + self.compare_and_swap(current, new, order) + } + + fn compare_exchange( + &self, + current: Self::Type, + new: Self::Type, + success: Ordering, + failure: Ordering, + ) -> Result { + self.compare_exchange(current, new, success, failure) + } + + fn compare_exchange_weak( + &self, + current: Self::Type, + new: Self::Type, + success: Ordering, + failure: Ordering, + ) -> Result { + self.compare_exchange_weak(current, new, success, failure) + } +} diff --git a/src/atomic_f64.rs b/src/atomic_f64.rs index dbce8c5..618bf42 100644 --- a/src/atomic_f64.rs +++ b/src/atomic_f64.rs @@ -811,3 +811,60 @@ impl PartialEq for AtomicF64 { self.load(Relaxed) == o.load(Relaxed) } } +#[cfg(feature = "atomic-traits")] +impl atomic_traits::Atomic for AtomicF64 { + type Type = f64; + + fn new(v: Self::Type) -> Self { + Self::new(v) + } + + fn get_mut(&mut self) -> &mut Self::Type { + self.get_mut() + } + + fn into_inner(self) -> Self::Type { + self.into_inner() + } + + fn load(&self, order: Ordering) -> Self::Type { + self.load(order) + } + + fn store(&self, val: Self::Type, order: Ordering) { + self.store(val, order) + } + + fn swap(&self, val: Self::Type, order: Ordering) -> Self::Type { + self.swap(val, order) + } + + fn compare_and_swap( + &self, + current: Self::Type, + new: Self::Type, + order: Ordering, + ) -> Self::Type { + self.compare_and_swap(current, new, order) + } + + fn compare_exchange( + &self, + current: Self::Type, + new: Self::Type, + success: Ordering, + failure: Ordering, + ) -> Result { + self.compare_exchange(current, new, success, failure) + } + + fn compare_exchange_weak( + &self, + current: Self::Type, + new: Self::Type, + success: Ordering, + failure: Ordering, + ) -> Result { + self.compare_exchange_weak(current, new, success, failure) + } +}