| Crates.io | composable-indexes |
| lib.rs | composable-indexes |
| version | 0.4.1 |
| created_at | 2025-04-07 19:55:32.28742+00 |
| updated_at | 2025-05-07 20:18:31.219405+00 |
| description | In-memory collections with composable indexes |
| homepage | |
| repository | https://github.com/utdemir/composable-indexes |
| max_upload_size | |
| id | 1624664 |
| size | 53,550 |
A Rust library for collections with flexible and composable in-memory indexes. The indexes stay in sync with the collection without any extra effort.
use composable_indexes::*;
struct Person { name: String, age: u32, ssn: String }
let mut collection = Collection::<Person, _>::new(
index::zip!(
// A hashtable for the ssn, for exact lookups
index::premap(|p: &Person| p.ssn.clone(), index::hashtable()),
// A btree index for age, for range lookups
index::premap(|p: &Person| p.age, index::btree()),
// Also keep track of the mean age
index::premap(|p: &Person| p.age, aggregations::mean()),
)
);
let alice = collection.insert(Person { name: "Alice".to_string(), /* ... */ });
collection.insert(Person { name: "Bob".to_string(), /* ... */ });
collection.adjust_mut(alice, |p| { p.age = 31; });
// ...
let q = collection.query();
// SSN lookup
let _found = q.0.get("123-45-6789");
// Query the oldest person
let _oldest = q.1.max_one();
// Query the mean age
let _mean_age = q.2;
ud/splat branch, but it adds yet another type parameter to the 'Index' trait, and I'm not sure if the tradeoff is worth it.