1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#2075 in Database interfaces

Download history 49418/week @ 2024-07-20 51307/week @ 2024-07-27 49159/week @ 2024-08-03 54453/week @ 2024-08-10 52363/week @ 2024-08-17 47516/week @ 2024-08-24 45629/week @ 2024-08-31 49869/week @ 2024-09-07 42211/week @ 2024-09-14 45522/week @ 2024-09-21 42254/week @ 2024-09-28 44375/week @ 2024-10-05 40702/week @ 2024-10-12 47900/week @ 2024-10-19 38746/week @ 2024-10-26 47869/week @ 2024-11-02

181,976 downloads per month
Used in 6 crates (3 directly)

MIT license

19KB
397 lines

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));
}

lib.rs:

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

Dependencies

~16KB