Crate ttmap[][src]

Expand description

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)

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.

Usage

use ttmap::TypeMap;

let mut map = TypeMap::new();

map.insert("string");

assert_eq!(*map.get::<&'static str>().unwrap(), "string");

map.insert(1u8);

assert_eq!(*map.get::<u8>().unwrap(), 1);

assert_eq!(map.get_or_default::<String>(), "");

Structs

Type-safe store, indexed by types.

Traits

Valid type for TypeMap