Skip to main content

Module buf

Module buf 

Source
Expand description

Buffer abstractions for zero-copy I/O operations.

This module provides buffer types and traits for efficient I/O without unnecessary allocations. The core abstraction is BufLike, which manages the lifecycle of buffers used in syscalls.

§Buffer Pool

The BufStore (requires buf feature) provides a pool of reusable 4096-byte buffers to avoid heap allocations. Each buffer is protected by a mutex for concurrent access.

use lio::buf::BufStore;

let pool = BufStore::default(); // 128 buffers

if let Some(buf) = pool.try_get() {
    // Got pooled buffer, no allocation
} else {
    // All buffers in use, fallback to Vec::with_capacity(4096)
}

§Feature zeroize

When the zeroize feature is enabled, LentBuffers are automatically and securely zeroed out on drop. This provides defense-in-depth against memory disclosure vulnerabilities by ensuring sensitive data doesn’t persist in pooled buffers.

This uses the zeroize crate, which guarantees that compiler optimizations won’t eliminate the zeroing operation.

Structs§

BufStore
A pool of reusable buffers for I/O operations.
LentBuf
A borrowed buffer from a BufStore pool.
LentBufIter

Traits§

BufLike
A interface over buffers.

Type Aliases§

BufResult
Result type for operations that return both a result and a buffer.