| Crates.io | computed_map |
| lib.rs | computed_map |
| version | 0.1.0 |
| created_at | 2025-08-25 08:19:34.541904+00 |
| updated_at | 2025-08-25 08:19:34.541904+00 |
| description | A Rust proc-macro crate for generating indexed maps with computed fields and indicies. |
| homepage | https://github.com/JeffDownie/computed_map |
| repository | |
| max_upload_size | |
| id | 1809202 |
| size | 39,479 |
A Rust proc-macro crate for generating indexed maps with computed fields and indices.
use computed_map::*;
generate_table! {
TestTable, u64, u64, // The name of the map struct, the key type, and the value type
PlusOne, |x: u64| -> u64 { x + 1 }, true
}
fn main() {
let mut table = TestTable::new();
let mut locked_table = table.lock();
locked_table.insert(42, 100);
locked_table.insert(43, 100);
table = locked_table.unlock();
table.len(); // 2
table.get(&42) // Some(&(42, MappedValuesStructTestTable { plus_one: 101 } ));
table.get_plus_one(&101); // Some(&BTreeSet::from([42, 43]));
}
Add to your Cargo.toml:
[dependencies]
computed_map = "0.1.0"
Then use the generate_table! macro to define your indexed map.
generate_table! {
TableName, KeyType, ValueType,
[ComputedName, ComputedFunction, AddIndex]*
}
TableName: Name of the generated table struct.KeyType: Type of the key.ValueType: Type of the value.ComputedName: Name of the computed value.ComputedFunction: Function to compute a value dependant on the original type. Must be a typed closureAddIndex: Whether to add an index over the computed field (true or false).You can specify multiple indices by repeating the triple: ComputedName, ComputedFunction, AddIndex.
Licensed under MIT.