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<'_>, TryClaimError>
pub fn try_claim(&mut self, len: usize) -> Result<WriteClaim<'_>, TryClaimError>
Attempts to claim space for a record with the given payload length.
Returns a WriteClaim that can be written to and then committed.
§Errors
TryClaimError::ZeroLengthiflenis zeroTryClaimError::Fullif the buffer is full
§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!.
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.