libdd-tinybytes

Crates.iolibdd-tinybytes
lib.rslibdd-tinybytes
version1.0.0
created_at2025-11-17 14:11:20.749527+00
updated_at2025-11-17 14:11:20.749527+00
descriptionTiny implementation of a bytes::Bytes like type that supports AsRef<[u8]>
homepagehttps://github.com/DataDog/libdatadog/tree/main/libdd-tinybytes
repositoryhttps://github.com/DataDog/libdatadog/tree/main/libdd-tinybytes
max_upload_size
id1936846
size44,508
libdatadog-owners (github:datadog:libdatadog-owners)

documentation

README

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

Commit count: 1422

cargo fmt