Skip to main content

StaticLendRing

Struct StaticLendRing 

Source
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>

Source

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).

Source

pub const fn capacity(&self) -> usize

Slot count (the const N).

Source

pub const fn slot_bytes(&self) -> usize

Per-slot byte capacity (the const BYTES).

Source

pub fn leased_count(&self) -> usize

Slots currently lent and not yet reclaimed.

Source

pub fn acquire(&self) -> Option<RingSlot<'_, N, BYTES>>

Reserve a free slot for capture, or None if all N are still in flight (ring full: the producer must wait for a downstream drop). Fill the returned handle, then publish it as a frame slice.

Source

pub fn contains(&self, ptr: *const u8) -> bool

True if ptr points inside one of this ring’s slots, the zero-copy witness a test uses to prove a received frame aliases the ring (no copy).

Trait Implementations§

Source§

impl<const N: usize, const BYTES: usize> Debug for StaticLendRing<N, BYTES>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, const BYTES: usize> Default for StaticLendRing<N, BYTES>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const N: usize, const BYTES: usize> Sync for StaticLendRing<N, BYTES>

Auto Trait Implementations§

§

impl<const N: usize, const BYTES: usize> !Freeze for StaticLendRing<N, BYTES>

§

impl<const N: usize, const BYTES: usize> !RefUnwindSafe for StaticLendRing<N, BYTES>

§

impl<const N: usize, const BYTES: usize> Send for StaticLendRing<N, BYTES>
where [UnsafeCell<[u8; BYTES]>; N]: Send, [Atomic<bool>; N]: Send,

§

impl<const N: usize, const BYTES: usize> Unpin for StaticLendRing<N, BYTES>
where [UnsafeCell<[u8; BYTES]>; N]: Unpin, [Atomic<bool>; N]: Unpin,

§

impl<const N: usize, const BYTES: usize> UnsafeUnpin for StaticLendRing<N, BYTES>

§

impl<const N: usize, const BYTES: usize> UnwindSafe for StaticLendRing<N, BYTES>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ElementBound for T
where T: Send,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.