https://github.com/doumanash/type-map
Trivial implementation of type-map
https://github.com/doumanash/type-map
Last synced: 2 months ago
JSON representation
Trivial implementation of type-map
- Host: GitHub
- URL: https://github.com/doumanash/type-map
- Owner: DoumanAsh
- License: bsl-1.0
- Created: 2020-01-15T22:16:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-11-24T07:14:27.000Z (over 1 year ago)
- Last Synced: 2024-05-02T00:10:18.943Z (about 1 year ago)
- Language: Rust
- Size: 22.5 KB
- Stars: 6
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ttmap (Trivial Type Map)
[](https://crates.io/crates/ttmap)
[](https://docs.rs/crate/ttmap/)
[](https://github.com/DoumanAsh/type-map/actions?query=workflow%3ARust)Trivial type-map implementation
Implementation uses type erased values with type as index.
Due to limitation of `TypeId` only types without non-static references are supported. (in future it can be changed)## Type erasure
Each inserted value is stored on heap, with type erased pointer, using type as key.
When value is retrieved, type information is used as key and pointer is casted to corresponding the type.
This is safe, because Rust allows cast back and forth between pointers as long as the pointer actually points to the type (which is the case).Static references are allowed, but in current implementation are stored on heap.
It might be changed in future.## Hash implementation
The map uses simplified `Hasher` that relies on fact that `TypeId` produces unique values only.
In fact there is no hashing under hood, and type's id is returned as it is.