1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#2464 in Database interfaces

Download history 207931/week @ 2025-09-14 190588/week @ 2025-09-21 195921/week @ 2025-09-28 184768/week @ 2025-10-05 196047/week @ 2025-10-12 183759/week @ 2025-10-19 186616/week @ 2025-10-26 187258/week @ 2025-11-02 195680/week @ 2025-11-09 184207/week @ 2025-11-16 162382/week @ 2025-11-23 172201/week @ 2025-11-30 179697/week @ 2025-12-07

722,341 downloads per month
Used in 29 crates (5 directly)

MIT license

19KB
397 lines

A type-based key value store where one value type is allowed for each key.


typemap-ors CI

A typesafe store keyed by types and containing different types of values.

Documentation

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

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::<KeyType>(Value(42));
    assert_eq!(*map.get::<KeyType>().unwrap(), Value(42));
}

Dependencies

~16KB