pub struct PubSubRing { /* private fields */ }Expand description
One-producer many-subscriber broadcast ring with per-subscriber positions.
Implementations§
Source§impl PubSubRing
impl PubSubRing
Sourcepub fn create_anon(capacity: usize) -> Result<Self>
pub fn create_anon(capacity: usize) -> Result<Self>
Construct an anonymous in-process pub/sub ring.
Sourcepub fn create(path: impl AsRef<Path>, capacity: usize) -> Result<Self>
pub fn create(path: impl AsRef<Path>, capacity: usize) -> Result<Self>
Construct a file-backed pub/sub ring. Cross-process via the OS page cache.
Sourcepub fn open(path: impl AsRef<Path>, expected_capacity: usize) -> Result<Self>
pub fn open(path: impl AsRef<Path>, expected_capacity: usize) -> Result<Self>
Open an existing file-backed pub/sub ring. Validates magic
- capacity.
Sourcepub fn create_from_shm(shm: ShmFile, capacity: usize) -> Result<Self>
pub fn create_from_shm(shm: ShmFile, capacity: usize) -> Result<Self>
Construct a fresh pub/sub ring on top of a named RAM-resident shared-memory backing.
Sourcepub fn open_from_shm(shm: ShmFile, expected_capacity: usize) -> Result<Self>
pub fn open_from_shm(shm: ShmFile, expected_capacity: usize) -> Result<Self>
Open an existing named ShmFs-backed pub/sub ring.
Sourcepub fn head(&self) -> u64
pub fn head(&self) -> u64
Producer’s published head. Equals the next position that
will be assigned to a publish call.
Sourcepub fn publish(&self, payload: &[u8]) -> u64
pub fn publish(&self, payload: &[u8]) -> u64
Publish one payload. Returns the absolute position assigned to this item. Caller MUST be the single producer.
Sourcepub fn read_at(
&self,
position: u64,
out: &mut [u8],
) -> Result<(), PubSubReadError>
pub fn read_at( &self, position: u64, out: &mut [u8], ) -> Result<(), PubSubReadError>
Read the payload at absolute position. The subscriber
supplies a buffer of at least PUBSUB_PAYLOAD_BYTES.
Returns Ok(()) on success (payload copied into out),
Err(Pending) when the position has not been published yet,
Err(Lost) when the slot has wrapped past position.