# rust-typemap **Repository Path**: rustup/rust-typemap ## Basic Information - **Project Name**: rust-typemap - **Description**: from crates.io - **Primary Language**: Rust - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-26 - **Last Updated**: 2021-11-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # `TypeMap` > A typesafe store keyed by types and containing different types of values. ## [Documentation](https://crates.fyi/crates/typemap/0.3.3) It provides functionality similar to AnyMap, but is more flexible because it allows for key-value pairs, rather than enforcing that keys and values are the same type. Key-value associations are defined through the `Key` trait, which uses an associated type parameter and trait coherence rules to enforce the invariants of `TypeMap`. ## Example ```rust extern crate typemap; use typemap::{TypeMap, Key}; struct KeyType; #[derive(Debug, PartialEq)] struct Value(i32); impl Key for KeyType { type Value = Value; } #[test] fn test_pairing() { let mut map = TypeMap::new(); map.insert::(Value(42)); assert_eq!(*map.get::().unwrap(), Value(42)); } ```