use std::marker::PhantomData;
use std::sync::Arc;
use crate::seqlock::lock::SeqLock;
pub struct Writer<T>
where
T: bytemuck::AnyBitPattern,
{
inner: Arc<SeqLock<T>>,
_not_sync: PhantomData<*const ()>,
}
impl<T> std::fmt::Debug for Writer<T>
where
T: bytemuck::AnyBitPattern,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Writer").finish_non_exhaustive()
}
}
unsafe impl<T> Send for Writer<T> where T: bytemuck::AnyBitPattern {}
impl<T> Writer<T>
where
T: bytemuck::AnyBitPattern,
{
pub(super) fn new(seqlock: Arc<SeqLock<T>>) -> Self {
Self {
inner: seqlock,
_not_sync: PhantomData,
}
}
#[inline]
pub fn write(&self, value: T) {
self.inner.write(value)
}
}
#[cfg(test)]
mod tests {
use super::*;
static_assertions::assert_impl_all!(Writer<u32>: Send);
static_assertions::assert_not_impl_any!(Writer<u32>: Sync, Clone, Copy);
static_assertions::assert_not_impl_any!(Arc<Writer<u32>>: Send, Sync, Copy);
}