low_latency_data_structures/seqlock/
writer.rs1use std::marker::PhantomData;
2use std::sync::Arc;
3
4use crate::seqlock::lock::SeqLock;
5
6pub struct Writer<T: bytemuck::AnyBitPattern> {
11 inner: Arc<SeqLock<T>>,
12 _not_sync: PhantomData<*const ()>,
14}
15
16impl<T: bytemuck::AnyBitPattern> std::fmt::Debug for Writer<T> {
17 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18 f.debug_struct("Writer").finish_non_exhaustive()
19 }
20}
21
22unsafe impl<T: bytemuck::AnyBitPattern> Send for Writer<T> {}
24
25impl<T: bytemuck::AnyBitPattern> Writer<T> {
26 pub(super) fn new(seqlock: Arc<SeqLock<T>>) -> Self {
27 Self {
28 inner: seqlock,
29 _not_sync: PhantomData,
30 }
31 }
32
33 #[inline]
48 pub fn write(&self, value: T) {
49 self.inner.write(value)
50 }
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 static_assertions::assert_impl_all!(Writer<u32>: Send);
59 static_assertions::assert_not_impl_any!(Writer<u32>: Sync, Clone, Copy);
61 static_assertions::assert_not_impl_any!(Arc<Writer<u32>>: Send, Sync, Copy);
62}