1 use std::cell::UnsafeCell; 2 use std::fmt; 3 use std::ops::Deref; 4 5 /// `AtomicU8` providing an additional `load_unsync` function. 6 pub(crate) struct AtomicU8 { 7 inner: UnsafeCell<std::sync::atomic::AtomicU8>, 8 } 9 10 unsafe impl Send for AtomicU8 {} 11 unsafe impl Sync for AtomicU8 {} 12 13 impl AtomicU8 { new(val: u8) -> AtomicU814 pub(crate) const fn new(val: u8) -> AtomicU8 { 15 let inner = UnsafeCell::new(std::sync::atomic::AtomicU8::new(val)); 16 AtomicU8 { inner } 17 } 18 } 19 20 impl Deref for AtomicU8 { 21 type Target = std::sync::atomic::AtomicU8; 22 deref(&self) -> &Self::Target23 fn deref(&self) -> &Self::Target { 24 // safety: it is always safe to access `&self` fns on the inner value as 25 // we never perform unsafe mutations. 26 unsafe { &*self.inner.get() } 27 } 28 } 29 30 impl fmt::Debug for AtomicU8 { fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result31 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { 32 self.deref().fmt(fmt) 33 } 34 } 35