#anda #db #serialization

anda_db_utils

An utility Rust library for Anda DB

3 unstable releases

Uses new Rust 2024

0.2.1 Aug 10, 2025
0.2.0 Aug 8, 2025
0.1.0 Jul 11, 2025

#2159 in Database interfaces

Download history 141/week @ 2025-07-09 13/week @ 2025-07-16 22/week @ 2025-07-23 301/week @ 2025-08-06 104/week @ 2025-08-13 144/week @ 2025-08-20 119/week @ 2025-08-27 91/week @ 2025-09-03

490 downloads per month
Used in 12 crates (4 directly)

MIT license

42KB
1K SLoC

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.

Dependencies

~0.7–1.3MB
~29K SLoC