use std::{cell::Cell, fmt::{Debug, Display, Formatter}, ops::Deref}; /// [`SyncCell`], but [`Sync`]. /// /// This is just an `Cell`, except it implements `Sync` /// if `T` implements `Sync`. pub struct SyncCell(Cell); unsafe impl Sync for SyncCell {} impl SyncCell { #[inline] pub const fn new(value: T) -> Self { Self(Cell::new(value)) } } impl Default for SyncCell { fn default() -> Self { Self::new(T::default()) } } impl Deref for SyncCell { type Target = Cell; #[inline] fn deref(&self) -> &Self::Target { &self.0 } } impl Clone for SyncCell { #[inline] fn clone(&self) -> SyncCell { SyncCell::new(self.get()) } } impl Debug for SyncCell { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { Debug::fmt(&self.get(), f) } } impl Display for SyncCell { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { Display::fmt(&self.get(), f) } }