Expand description
High-performance conflation slots for latest-value-wins scenarios.
Two variants based on reader topology:
spsc— Single producer, single consumer. Lowest overhead.spmc— Single producer, multiple consumers.SharedReaderisClone.
Both use a seqlock internally: the writer increments a sequence counter, copies data via word-at-a-time atomics, and increments again. Readers speculatively copy and retry if the sequence changed.
§The Pod Trait
Types must implement Pod (Plain Old Data) — no heap allocations,
no drop glue, byte-copyable. Any Copy type implements Pod automatically.
use nexus_slot::Pod;
#[repr(C)]
struct OrderBook {
bids: [f64; 20],
asks: [f64; 20],
sequence: u64,
}
// SAFETY: OrderBook is just bytes — no heap allocations
unsafe impl Pod for OrderBook {}§Examples
#[derive(Copy, Clone, Default)]
struct Quote { bid: f64, ask: f64, seq: u64 }
// SPSC — single reader
let (mut writer, mut reader) = nexus_slot::spsc::slot::<Quote>();
writer.write(Quote { bid: 100.0, ask: 100.05, seq: 1 });
assert_eq!(reader.read().unwrap().seq, 1);#[derive(Copy, Clone, Default)]
struct Quote { bid: f64, ask: f64, seq: u64 }
// SPMC — multiple readers
let (mut writer, mut reader1) = nexus_slot::spmc::shared_slot::<Quote>();
let mut reader2 = reader1.clone();
writer.write(Quote { bid: 100.0, ask: 100.05, seq: 1 });
assert!(reader1.read().is_some());
assert!(reader2.read().is_some()); // independent consumptionModules§
- spmc
- Single-producer, multiple-consumer conflation slot.
- spsc
- Single-producer, single-consumer conflation slot.
Traits§
- Pod
- Marker trait for types safe to use in a conflated slot.