pub struct StaticLendRing<const N: usize, const BYTES: usize> { /* private fields */ }Expand description
A fixed, heap-free ring of byte buffers that lends each slot to the pipeline
zero-copy as a SystemSlice, the capture-side sibling of
StaticBufferPool (which moves an owned buffer out; this keeps the bytes in
place and lends a borrow). It models a DMA capture ring: N slots of BYTES
bytes live inline (no alloc), the producer fills the next free slot and
publishes it as a frame that borrows the slot, and the
slot is reclaimed when that frame is dropped downstream (the lend’s free
callback clears the lease). A slot is never reused while still lent, so the
producer stalls when every slot is in flight, the genuine ring back-pressure.
The borrow is runtime-guarded, not a Rust lifetime: a PipelinePacket crosses
the OutputSink / stack-channel boundary by value ('static), so the lent
slice is the 'static foreign-lend (SystemSlice::from_foreign) with the
lease standing in for the borrow. new() is not const; place the ring in a
StaticCell (or a static via a const-init wrapper) on real hardware, or keep
it alive on the stack for the duration of a block_on pipeline.
Implementations§
Source§impl<const N: usize, const BYTES: usize> StaticLendRing<N, BYTES>
impl<const N: usize, const BYTES: usize> StaticLendRing<N, BYTES>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Build a ring of N zeroed BYTES-sized slots. const, so the ring
can live in a static (the DMA-ring idiom), which is also what makes
the zero-copy lend safe without unsafe in application code: a
&'static ring trivially outlives every published frame (see e.g.
g2g-mcu’s GrabberSrc::new).
Sourcepub const fn slot_bytes(&self) -> usize
pub const fn slot_bytes(&self) -> usize
Per-slot byte capacity (the const BYTES).
Sourcepub fn leased_count(&self) -> usize
pub fn leased_count(&self) -> usize
Slots currently lent and not yet reclaimed.