#byte-buffer #rc #serialization #zero-copy #immutability #utf-8 #serde #datadog

libdd-tinybytes

Tiny implementation of a bytes::Bytes like type that supports AsRef<[u8]>

2 stable releases

1.1.0 Feb 10, 2026
1.0.0 Nov 17, 2025

#953 in Encoding

Download history 431/week @ 2025-11-21 339/week @ 2025-11-28 646/week @ 2025-12-05 540/week @ 2025-12-12 288/week @ 2025-12-19 252/week @ 2025-12-26 328/week @ 2026-01-02 1155/week @ 2026-01-09 754/week @ 2026-01-16 872/week @ 2026-01-23 1419/week @ 2026-01-30 20165/week @ 2026-02-06 23757/week @ 2026-02-13 46544/week @ 2026-02-20 59442/week @ 2026-02-27 120394/week @ 2026-03-06

261,807 downloads per month
Used in 6 crates (3 directly)

Apache-2.0

36KB
687 lines

libdd-tinybytes

A lightweight alternative to bytes::Bytes providing immutable, reference-counted byte buffers with zero-copy cloning and slicing.

Overview

libdd-tinybytes provides an immutable byte buffer type similar to bytes::Bytes with a focus on simplicity and AsRef<[u8]> support. It uses reference counting to enable efficient zero-copy operations.

Types

Bytes

An immutable byte buffer that supports:

  • Zero-copy cloning: Creating new Bytes instances shares the underlying buffer through reference counting
  • Zero-copy slicing: Extracting subslices without copying the underlying data
  • Static buffers: Efficient handling of &'static [u8] without reference counting overhead
  • Thread safety: Implements Send + Sync for safe use across threads
  • AsRef implementation: Directly usable as &[u8]

BytesString

A UTF-8 validated string type built on top of Bytes (enabled with the bytes_string feature):

  • UTF-8 validation: Ensures data is valid UTF-8 at construction time
  • String interface: Provides AsRef<str> and Borrow<str> implementations
  • Zero-copy operations: Inherits efficient cloning and slicing from Bytes

Implementation Details

The crate uses a custom reference counting implementation optimized for its specific use case, tracking only strong references. Individual deallocations do not free memory; instead, memory is reclaimed when the last reference is dropped.

Feature Flags

  • bytes_string: Enable the BytesString UTF-8 validated string type
  • serialization: Enable serde support for serialization

License

Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/

SPDX-License-Identifier: Apache-2.0

Dependencies

~150KB