anda_db_utils

Crates.ioanda_db_utils
lib.rsanda_db_utils
version0.2.1
created_at2025-07-11 02:47:05.7573+00
updated_at2025-08-10 13:10:24.019492+00
descriptionAn utility Rust library for Anda DB.
homepage
repositoryhttps://github.com/ldclabs/anda_db/tree/main/rs/anda_db_utils
max_upload_size
id1747351
size45,045
0xZensh (zensh)

documentation

README

Anda DB Utils

anda_db_utils is a utility Rust library for Anda DB, providing helpful extensions and data structures.

Features

  • Pipe Trait: Enables functional-style method chaining.
  • UniqueVec<T>: A Vec that ensures all its elements are unique.
  • CountingWriter: A writer that counts bytes, useful for determining the size of serialized data without allocation.

Usage

Pipe Trait

The Pipe trait allows you to chain functions in a fluent, readable way.

use anda_db_utils::Pipe;

let result = 5.pipe(|x| x * 2).pipe(|x| x + 1);
assert_eq!(result, 11);

UniqueVec

UniqueVec<T> is a vector that automatically handles uniqueness of its elements, backed by a HashSet for efficiency.

use anda_db_utils::UniqueVec;

let mut unique_vec = UniqueVec::from(vec![1, 2, 3]);

// Pushing an existing item does nothing
unique_vec.push(2);
assert_eq!(unique_vec.as_ref(), &[1, 2, 3]);

// Pushing a new item adds it to the vector
unique_vec.push(4);
assert_eq!(unique_vec.as_ref(), &[1, 2, 3, 4]);

// Extend with a mix of new and existing items
unique_vec.extend(vec![3, 5, 6]);
assert_eq!(unique_vec.as_ref(), &[1, 2, 3, 4, 5, 6]);

CountingWriter

CountingWriter can be used to calculate the size of data when serialized, for example with CBOR, without actually writing to memory.

use anda_db_utils::CountingWriter;
use serde::Serialize;

#[derive(Serialize)]
struct MyData {
    id: u32,
    name: String,
}

let data = MyData { id: 1, name: "test".to_string() };
let size = estimate_cbor_size(&data);

println!("Serialized size: {} bytes", size);

License

Copyright © 2025 LDC Labs.

ldclabs/anda-db is licensed under the MIT License. See LICENSE for the full license text.

Commit count: 0

cargo fmt