Skip to main content

BufferPool

Struct BufferPool 

Source
pub struct BufferPool<const SLOTS: usize, const LEN: usize> { /* private fields */ }
Expand description

Fixed-capacity pool of LEN-byte buffers. Declare as a static and call Self::claim to obtain a BufferLease.

§Const-constructible

BufferPool::new() is const fn, so pools can be declared as static items initialized at link time with no runtime cost.

§Minimum slot length

LEN must be at least 16 bytes — the size of a SOME/IP header — or the client silently drops all inbound and rejects all sends. A compile-time const assertion in Self::new enforces this floor. 16 is only the absolute header minimum: in practice a slot must hold the largest expected message (header + payload), realistically one full UDP datagram (see crate::UDP_BUFFER_SIZE).

§Synchronization

Each slot has an independent AtomicBool claimed flag. claim() scans for the first free slot and atomically claims it via compare_exchange(false, true, AcqRel, Acquire). Drop releases via store(false, Release). No global lock is taken; claim and release are individually linearizable.

Implementations§

Source§

impl<const SLOTS: usize, const LEN: usize> BufferPool<SLOTS, LEN>

Source

pub const fn new() -> Self

Create a new, empty pool. All slots are free.

§Panics (compile-time)

A const assertion rejects LEN < 16 at compile time: a slot must be large enough to hold a 16-byte SOME/IP header, otherwise the client silently drops all inbound and rejects all sends.

Source

pub fn claim(&'static self) -> Option<BufferLease>

Claim a free slot, returning a BufferLease, or None if all SLOTS are in use.

The returned buffer is zeroed before hand-out so a reused slot never leaks the previous tenant’s bytes.

Source§

impl<const SLOTS: usize, const LEN: usize> BufferPool<SLOTS, LEN>

Source

pub fn claim_arc(self: &Arc<Self>) -> Option<BufferLease>

Claim a free slot from an Arc-backed pool, returning a BufferLease that holds an Arc clone to keep the pool alive for the lease’s lifetime, or None if all SLOTS are in use.

This is the heap-backed counterpart to Self::claim: the static-pool path uses &'static self and stores _owner: None; this path stores _owner: Some(arc.clone()) so the pool’s backing store (and the slot’s claimed flag) stay valid until the last lease and provider drop. Only compiled where alloc is available (the _alloc feature), so the bare-metal client,bare_metal build stays allocation-free.

Trait Implementations§

Source§

impl<const SLOTS: usize, const LEN: usize> Debug for BufferPool<SLOTS, LEN>

Source§

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

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

impl<const SLOTS: usize, const LEN: usize> Default for BufferPool<SLOTS, LEN>

Source§

fn default() -> Self

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

impl<const SLOTS: usize, const LEN: usize> Sync for BufferPool<SLOTS, LEN>

Auto Trait Implementations§

§

impl<const SLOTS: usize, const LEN: usize> !Freeze for BufferPool<SLOTS, LEN>

§

impl<const SLOTS: usize, const LEN: usize> !RefUnwindSafe for BufferPool<SLOTS, LEN>

§

impl<const SLOTS: usize, const LEN: usize> Send for BufferPool<SLOTS, LEN>

§

impl<const SLOTS: usize, const LEN: usize> Unpin for BufferPool<SLOTS, LEN>

§

impl<const SLOTS: usize, const LEN: usize> UnsafeUnpin for BufferPool<SLOTS, LEN>

§

impl<const SLOTS: usize, const LEN: usize> UnwindSafe for BufferPool<SLOTS, LEN>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more