HeapBuffer

Type Alias HeapBuffer 

Source
pub type HeapBuffer = CircularBuffer<Vec<u8>>;
Available on crate feature alloc only.
Expand description

A circular buffer backed by a heap-allocated Vec<u8>.

Requires the alloc feature (enabled by default).

Aliased Type§

pub struct HeapBuffer { /* private fields */ }

Implementations§

Source§

impl HeapBuffer

Source

pub fn new(capacity: usize) -> Self

Creates a new buffer with the specified capacity.

This allocates a Vec of capacity bytes filled with zeros.

§Panics

Panics if capacity is 0.

§Examples
use ringo_buff::HeapBuffer;

let buf = HeapBuffer::new(1024);
assert_eq!(buf.capacity(), 1024);
Source

pub fn try_resize(&mut self, new_capacity: usize) -> Result<(), usize>

Attempts to resize the buffer to a new_capacity.

§Growing

If new_capacity is larger than the current capacity, the buffer is extended.

§Shrinking

If new_capacity is smaller, the buffer attempts to shrink.

  • This operation forces the buffer to become contiguous (see make_contiguous).
  • The operation fails if the active data (remaining()) is larger than new_capacity.
§Errors

Returns Err(usize) if the buffer cannot be shrunk because it currently holds too much data. The error value is the number of bytes that must be consumed (read) before this resize can succeed.

§Panics

Panics if new_capacity is 0.

Trait Implementations§

Source§

impl From<Vec<u8>> for HeapBuffer

Source§

fn from(value: Vec<u8>) -> Self

Converts an existing Vec<u8> into a HeapBuffer, reusing the Vec as the storage mechanism for the buffer.