Skip to main content

PoolBuffer

Struct PoolBuffer 

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

Fixed-capacity byte buffer that can be filled like Vec<u8> — but does not do a heap realloc. Overflow is reported via Result, not via panic!.

Layout: [u8; CAP] + len: u16 (max 65 535 bytes per buffer). This is enough for DDS hot-path samples up to 1.5 kB; larger samples continue to go through the alloc path.

Implementations§

Source§

impl<const CAP: usize> PoolBuffer<CAP>

Source

pub const fn new() -> Self

Creates an empty buffer.

CAP must be <= u16::MAX as usize — for larger values every mutation is rejected with PoolBufferError::CapacityTooLarge.

Source

pub const fn len(&self) -> usize

Current length (bytes written).

Source

pub const fn is_empty(&self) -> bool

true when no bytes have been written.

Source

pub const fn capacity(&self) -> usize

Static capacity.

Source

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

Read-only slice over the written bytes.

Source

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

Mutable slice over the uninitialized tail (capacity − len).

Source

pub fn clear(&mut self)

Resets the contents to len = 0. O(1), no memzero.

Source

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

Appends data to the end. Errors if the buffer would be full.

§Errors

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

Source

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

Writes a single byte. Errors when full.

§Errors

PoolBufferError::Overflow when the buffer is full.

Source

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

Sets the length explicitly. Used after a spare_capacity_mut write access by a codec backend.

§Errors

PoolBufferError::Overflow when 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.