computed_map 0.1.0

A Rust proc-macro crate for generating indexed maps with computed fields and indicies.
Documentation
# computed_map


[![Crates.io](https://img.shields.io/crates/v/computed_map.svg)](https://crates.io/crates/computed_map)
[![Docs.rs](https://docs.rs/computed_map/badge.svg)](https://docs.rs/computed_map)

A Rust proc-macro crate for generating indexed maps with computed fields and indices.

## Features


- **Procedural macro** to generate map types with computed indices.
- Supports multiple computed indices per map.
- Automatically maintains indices as values are inserted or removed.

## Example


```rust
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]));
}
```

## Usage


Add to your `Cargo.toml`:

```toml
[dependencies]
computed_map = "0.1.0"
```

Then use the `generate_table!` macro to define your indexed map.

## Macro Syntax


```rust
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 closure
- `AddIndex`: Whether to add an index over the computed field (`true` or `false`).

You can specify multiple indices by repeating the triple: `ComputedName, ComputedFunction, AddIndex`.

## License


Licensed under [MIT](LICENSE).

## Links


- [Documentation]https://docs.rs/computed_map
- [Crate on crates.io]https://crates.io/crates/computed_map
- [Repository]https://github.com/JeffDownie/computed_map