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>
impl<const CAP: usize> PoolBuffer<CAP>
Sourcepub const fn new() -> Self
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.
Sourcepub fn spare_capacity_mut(&mut self) -> &mut [u8] ⓘ
pub fn spare_capacity_mut(&mut self) -> &mut [u8] ⓘ
Mutable slice over the uninitialized tail (capacity − len).
Sourcepub fn extend_from_slice(&mut self, data: &[u8]) -> Result<(), PoolBufferError>
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.
Sourcepub fn set_len(&mut self, new_len: usize) -> Result<(), PoolBufferError>
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.