Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/storycraft/fn-map
Abstraction around HashMap. Uses closure to compute and store value.
https://github.com/storycraft/fn-map
hashmap rust type-store
Last synced: 2 months ago
JSON representation
Abstraction around HashMap. Uses closure to compute and store value.
- Host: GitHub
- URL: https://github.com/storycraft/fn-map
- Owner: storycraft
- Created: 2023-06-29T07:48:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-15T05:10:02.000Z (6 months ago)
- Last Synced: 2024-10-06T21:37:01.902Z (3 months ago)
- Topics: hashmap, rust, type-store
- Language: Rust
- Homepage:
- Size: 64.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FnMap
FnMap is a abstraction around the HashMap, like TypeMap. But uses closure's type(each closure's type is *unique* in Rust) as key and stores produced *value*. Allowing to be used like effective low cost dependency injection container.## Usage
```rust
use fn_map::FnMap;let map = FnMap::new();
fn one() -> i32 {
println!("one computed");
1
}// get or compute(and insert) value using given closure. The closure depends on value of `one` function to compute its output.
let a = *map.get(|| map.get(one) + 1);
dbg!(a);// b is *not* a because each closure's type is unique
let b = *map.get(|| map.get(one) + 1);
dbg!(b);// get or compute(and insert) value using give function. But will not compute since it is computed already when producing a.
let c = *map.get(one);
dbg!(c);
```will output
```bash
one computed
a = 2
b = 2
c = 1
```# License
MIT