#![doc = include_str!("../README.md")]
#![no_std]
#[macro_use]
mod macros;
mod atomic;
mod integer;
mod signed;
mod unsigned;
#[cfg(test)]
mod tests;
pub use self::atomic::PrimitiveAtomic;
pub use self::integer::PrimitiveAtomicInteger;
pub use self::signed::PrimitiveAtomicSigned;
pub use self::unsigned::PrimitiveAtomicUnsigned;
trait Sealed {}
pub trait AtomicPrimitive: Sized + Copy + Send + Sync {
type Atomic: PrimitiveAtomic<Value = Self>;
#[inline]
fn to_atomic(self) -> Self::Atomic {
Self::Atomic::new(self)
}
}
pub type Atomic<T> = <T as AtomicPrimitive>::Atomic;
macro_rules! impl_atomic_primitive {
($($Primitive:ty => $AtomicType:ty),+ $(,)?) => {$(
impl AtomicPrimitive for $Primitive {
type Atomic = $AtomicType;
}
)+};
}
use core::sync::atomic::{
AtomicBool, AtomicI8, AtomicI16, AtomicI32, AtomicIsize, AtomicU8, AtomicU16, AtomicU32,
AtomicUsize,
};
#[cfg(target_has_atomic = "64")]
use core::sync::atomic::{AtomicI64, AtomicU64};
impl_atomic_primitive! {
bool => AtomicBool,
u8 => AtomicU8,
u16 => AtomicU16,
u32 => AtomicU32,
usize => AtomicUsize,
i8 => AtomicI8,
i16 => AtomicI16,
i32 => AtomicI32,
isize => AtomicIsize,
}
#[cfg(target_has_atomic = "64")]
impl_atomic_primitive! {
u64 => AtomicU64,
i64 => AtomicI64,
}