Skip to main content

PoolBuffer

Struct PoolBuffer 

Source
pub struct PoolBuffer<const CAP: usize> { /* private fields */ }
Expand description

Fixed-Capacity Byte-Buffer, der wie Vec<u8> befuellt werden kann — aber keinen Heap-Realloc macht. Ueberlauf wird per Result gemeldet, nicht per panic!.

Layout: [u8; CAP] + len: u16 (max 65 535 Bytes pro Buffer). Fuer DDS-Hot-Path-Samples bis 1.5 kB ist das genug; groessere Samples laufen weiter ueber den alloc-Pfad.

Implementations§

Source§

impl<const CAP: usize> PoolBuffer<CAP>

Source

pub const fn new() -> Self

Erzeugt einen leeren Buffer.

CAP muss <= u16::MAX as usize sein — bei groesseren Werten lehnt jede Mutation mit PoolBufferError::CapacityTooLarge ab.

Source

pub const fn len(&self) -> usize

Aktuelle Laenge (Bytes geschrieben).

Source

pub const fn is_empty(&self) -> bool

true wenn keine Bytes geschrieben sind.

Source

pub const fn capacity(&self) -> usize

Statische Kapazitaet.

Source

pub fn as_slice(&self) -> &[u8]

Lesender Slice ueber die geschriebenen Bytes.

Source

pub fn spare_capacity_mut(&mut self) -> &mut [u8]

Mutabler Slice ueber den uninitialisierten Tail (Capacity-len).

Source

pub fn clear(&mut self)

Setzt den Inhalt zurueck auf len = 0. O(1), kein Memzero.

Source

pub fn extend_from_slice(&mut self, data: &[u8]) -> Result<(), PoolBufferError>

Haengt data ans Ende. Fehler wenn der Buffer voll waere.

§Errors

PoolBufferError::Overflow wenn self.len() + data.len() > CAP. PoolBufferError::CapacityTooLarge wenn CAP > u16::MAX.

Source

pub fn push(&mut self, byte: u8) -> Result<(), PoolBufferError>

Schreibt ein einzelnes Byte. Fehler bei Vollheit.

§Errors

PoolBufferError::Overflow wenn der Buffer voll ist.

Source

pub fn set_len(&mut self, new_len: usize) -> Result<(), PoolBufferError>

Setzt die Laenge explizit. Genutzt nach einem spare_capacity_mut- Schreibzugriff durch ein Codec-Backend.

§Errors

PoolBufferError::Overflow wenn new_len > CAP.

Trait Implementations§

Source§

impl<const CAP: usize> AsRef<[u8]> for PoolBuffer<CAP>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<const CAP: usize> Debug for PoolBuffer<CAP>

Source§

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

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

impl<const CAP: usize> Default for PoolBuffer<CAP>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<const CAP: usize> Freeze for PoolBuffer<CAP>

§

impl<const CAP: usize> RefUnwindSafe for PoolBuffer<CAP>

§

impl<const CAP: usize> Send for PoolBuffer<CAP>

§

impl<const CAP: usize> Sync for PoolBuffer<CAP>

§

impl<const CAP: usize> Unpin for PoolBuffer<CAP>

§

impl<const CAP: usize> UnsafeUnpin for PoolBuffer<CAP>

§

impl<const CAP: usize> UnwindSafe for PoolBuffer<CAP>

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