Expand description
Circular (ring) buffer implementation with secure memory management.
§Memory Safety
- Memory is lazily allocated on first write.
- All data is securely zeroed on drop via
zeroize. free()andburn_free()provide explicit cleanup for session termination.
§Performance
- Power-of-2 sizes use bitwise AND for wrapping (preferred).
- Non-power-of-2 sizes use standard modulo.
write()is a single-pass, at-most-two-copy_from_slicepath — no per-byte loop.- Borrow conflicts are avoided by extracting
Copyfields into locals before borrowingself.data, so Rust’s field-splitting NLL is never needed.
§Fixed Issues (vs original)
write_ptrused to panic when a write crossed the ring boundary. It now returnsBufferError::WouldWrapso callers can fall back towrite(). A newwrite_slices_mutmethod gives true zero-copy two-part access.readandwritecomputed positions by callingself.wrap_pos()while holding a borrow onself.data, causing borrow-checker issues. Both now use local copies ofsize/is_pow2and inline the arithmetic.writelooped over the data in chunks even when a simple two-segmentcopy_from_slicesuffices — replaced with a branch-free two-copy path.
Structs§
- Circular
Buffer - A circular (ring) buffer for efficient streaming data.