Crate bufkit

Source
Expand description

bufkit

Providing Buf and BufMut for working with byte buffers. bufkit focuses on predictable memory usage and comprehensive error handling.

github LoC Build codecov

docs.rs crates.io crates.io license

§Features

bufkit prioritizes explicit control and detailed error reporting, making it suitable for applications where memory behavior must be predictable and errors need comprehensive handling.

  • Multiple error handling strategies - Choose between panicking, Option, or detailed Result types
  • Buffer segmentation - Create independent views of buffer data
  • Offset operations - Built-in methods for writing/reading at specific positions
  • Embedded friendly - Support both no-alloc and no-std.
  • Sans-I/O friendly - Works purely on memory buffers without hidden allocations or I/O operations, providing predictable behavior and detailed error information that helps with protocol state management and partial data handling
    • No hidden allocations - Write operations work directly on provided memory
    • Retry-friendly - try_* methods provide detailed error information (requested vs available bytes) enabling robust retry logic and graceful error recovery

§Installation

[dependencies]
bufkit = "0.3"
  • Enable LEB128 encoding/decoding methods

    [dependencies]
    bufkit = { version = "0.3", features = ["varing"] }

§Alternatives

  • bytes::{Buf, BufMut}: Buffer traits for the bytes may or may not be stored in contiguous memory.
  • buffer-trait: A Buffer trait for reading into uninitialized buffers.
§License

bufkit is under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE, LICENSE-MIT for details.

Copyright (c) 2025 Al Liu.

Modules§

error
Errors buffer I/O

Structs§

Peeker
A peeker for reading from a buffer without advancing the original buffer’s cursor.
WriteBuf
A wrapper around any type that implements BufMut for improved ergonomics in generic code.

Traits§

Buf
A trait for implementing custom buffers that can read and navigate through byte sequences.
BufExt
Extension trait for Buf that provides additional methods
BufMut
A trait for implementing custom buffers that can store and manipulate byte sequences.
BufMutExt
A trait that extends BufMut with additional methods.
Varintvaring
A trait for types that can be encoded as variable-length integers (varints).