Expand description
§Photon Ring
Ultra-low-latency SPMC/MPMC pub/sub using stamped ring buffers.
no_std compatible (requires alloc). The topology module uses
OS threads and is available on Linux, macOS, Windows, and other
supported platforms.
§Key design
- Seqlock per slot — stamp and payload share a cache line; readers never take a lock, writers never allocate.
T: Pod— restricts payloads to plain-old-data types that carry no padding and where every bit pattern is valid, so a torn seqlock read yields a value that is discarded rather than an invalid one.- Per-consumer cursor — zero contention between subscribers.
- Single-producer — no write-side synchronisation; the seqlock invariant
is upheld by
&mut selfonPublisher::publish. atomic-slotsfeature — formally sound variant that usesAtomicU64stripes instead ofwrite_volatile. Zero cost on x86-64. See theatomic-slotsfeature flag.- Arbitrary capacity — any ring size >= 2 via Lemire fastmod; power-of-two uses bitwise AND (zero regression).
- Companion crates —
photon-ring-asyncfor runtime-agnostic async wrappers,photon-ring-metricsfor framework-agnostic observability.
§Which ring
channel()— lossyPodbroadcast; the publisher never blocks, and a subscriber that falls behind observesLagged { skipped }.channel_bounded()— per-consumer contracts on one ring:subscribe()gates the publisher and loses nothing,subscribe_lossy()can never stall it.channel_mpmc()— many producing threads; delivery is lossy only.event_channel()— payloads that own heap data (String,Vec, enums); slots are mutated in place and every subscriber gates the publisher.Photon/TypedBus— string-keyed topics, each an independent lossy ring.topology— dedicated-thread pipelines and terminal consumers.
§Quick start
// Low-level SPMC channel
let (mut pub_, subs) = photon_ring::channel::<u64>(64);
let mut sub = subs.subscribe();
pub_.publish(42);
assert_eq!(sub.try_recv(), Ok(42));
// Named-topic bus
let bus = photon_ring::Photon::<u64>::new(64);
let mut p = bus.publisher("topic-a");
let mut s = bus.subscribe("topic-a");
p.publish(7);
assert_eq!(s.try_recv(), Ok(7));Re-exports§
pub use barrier::DependencyBarrier;pub use channel::channel;pub use channel::channel_bounded;pub use channel::channel_mpmc;pub use channel::Drain;pub use channel::MpPublisher;pub use channel::PublishError;pub use channel::Publisher;pub use channel::Subscribable;pub use channel::Subscriber;pub use channel::TryRecvError;pub use event::event_channel;pub use event::EventPublisher;pub use event::EventSubscribable;pub use event::EventSubscriber;pub use wait::WaitStrategy;
Modules§
- affinity
- CPU core affinity helpers for deterministic cross-core latency.
- barrier
- Consumer dependency barriers for pipeline-style ordering.
- channel
- event
- A ring for values that are not
Pod. - mem
- Platform-specific memory control for ring buffer allocation.
- topology
- Builder-pattern topology for multi-stage processing pipelines.
- wait
- Wait strategies for blocking receive operations.
Structs§
- Padded
- Cache-line padding to prevent false sharing between hot atomics.
- Photon
- Named-topic pub/sub bus.
- Shutdown
- A shared shutdown signal for coordinating graceful termination.
- Typed
Bus - A topic bus that supports different message types per topic.
Traits§
- Pod
- Marker trait for types safe to use with seqlock-stamped ring buffers.
Derive Macros§
- Derive
Message - Derive macro that generates a Pod-compatible wire struct from a domain struct.
- Derive
Pod - Derive macro for the
Podtrait. Requires thederivefeature.