Crate ringo_buff

Crate ringo_buff 

Source
Expand description

§ringo-buff

Ring buffers for bytes, with heap and stack storage.

A simple, predictable ring buffer (circular buffer) implementation supporting both stack and heap storage strategies.

This crate provides a simple API for managing bytes in a circular buffer, useful for I/O buffering, streaming data, etc. It can be used without allocating and should be usable in a no_std environment.

§Quick Start

Choose your storage strategy:

  • HeapBuffer: Backed by a Vec<u8>. Best for dynamic sizes or large buffers. Supports resizing at runtime.
  • StackBuffer: Backed by an array. Best for fixed, small sizes where allocation is undesirable.
use ringo_buff::HeapBuffer;

// Create a buffer with 1024 bytes capacity
let mut buf = HeapBuffer::new(1024);

// Write data (advances write cursor)
let (first, _) = buf.as_mut_slices();
first[..3].copy_from_slice(b"foo");
buf.commit(3);

// Read data (advances read cursor)
let (first, _) = buf.as_slices();
assert_eq!(first, b"foo");
buf.consume(3);

§Feature Flags

  • alloc (default): Enables HeapBuffer and Vec support.
  • buf-trait: Implements bytes::Buf and bytes::BufMut traits.
  • zeroize: Clears memory on drop via the zeroize crate.
  • hybrid-array: Enables hybrid-array support for StackBuffer, allowing sizes to be defined via types (e.g., U1024).

Structs§

CircularBuffer
The core ring buffer logic generic over storage S.

Traits§

ArraySizehybrid-array
Trait which associates a usize size and ArrayType with a typenum-provided Unsigned integer.

Type Aliases§

HeapBufferalloc
A circular buffer backed by a heap-allocated Vec<u8>.
StackBufferhybrid-array
A circular buffer backed by hybrid_array::Array.