pub struct Producer { /* private fields */ }Expand description
Producer endpoint of the SPSC ring buffer.
Use try_claim to claim space for writing.
Implementations§
Source§impl Producer
impl Producer
Sourcepub fn try_claim(&mut self, len: usize) -> Result<WriteClaim<'_>, BufferFull>
pub fn try_claim(&mut self, len: usize) -> Result<WriteClaim<'_>, BufferFull>
Attempts to claim space for a record with the given payload length.
Returns a WriteClaim that can be written to and then committed.
§Errors
Returns BufferFull if the buffer has no space for the record.
§Panics
Panics if len == 0. The wire format reserves len == 0 as the
“uncommitted” sentinel — letting it through would silently hang the
consumer. Aborting a non-zero claim is fully supported (drop the
WriteClaim without committing); only claiming zero bytes upfront
is forbidden.
§Safety Contract
len must not exceed LEN_MASK. On 64-bit this is ~9.2 exabytes
(unreachable in practice). On 32-bit, records >2GB could set
SKIP_BIT and corrupt the stream — enforced with assert!.
On 64-bit this is checked with debug_assert! only.
Sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
Best-effort hint: returns true if the consumer has likely been dropped.
Uses Arc::strong_count which is inherently racy — the count can
change between the check and the caller’s next action. Suitable for
graceful shutdown detection, not for correctness. For reliable
disconnection detection, use the channel layer (channel::spsc)
which tracks disconnection via dedicated atomic flags.