#typemap #hash-map

ttmap

Trivial implementation of type map

6 releases

0.3.0 Nov 24, 2023
0.2.1 Sep 8, 2022
0.2.0 Dec 22, 2021
0.1.2 Jun 4, 2020
0.1.0 Jan 18, 2020

#886 in Data structures

Download history 80/week @ 2024-07-17 62/week @ 2024-07-24 113/week @ 2024-07-31 29/week @ 2024-08-07 163/week @ 2024-08-14 12/week @ 2024-08-21 12/week @ 2024-08-28 16/week @ 2024-09-04 25/week @ 2024-09-11 24/week @ 2024-09-18 134/week @ 2024-09-25 43/week @ 2024-10-02 24/week @ 2024-10-09 59/week @ 2024-10-16 26/week @ 2024-10-23 15/week @ 2024-10-30

125 downloads per month

BSL-1.0 license

15KB
328 lines

ttmap (Trivial Type Map)

Crates.io Documentation Build

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.

Requirements:

  • alloc with enabled global allocator

No runtime deps