19 unstable releases (3 breaking)

Uses old Rust 2015

0.3.3 Jun 12, 2015
0.3.0 Apr 25, 2015
0.0.12 Mar 30, 2015
0.0.5 Dec 23, 2014
0.0.4 Nov 28, 2014

#47 in #type-parameters

Download history 5105/week @ 2023-11-23 5143/week @ 2023-11-30 4833/week @ 2023-12-07 5725/week @ 2023-12-14 3488/week @ 2023-12-21 3420/week @ 2023-12-28 4320/week @ 2024-01-04 5025/week @ 2024-01-11 5010/week @ 2024-01-18 5413/week @ 2024-01-25 4942/week @ 2024-02-01 5238/week @ 2024-02-08 6016/week @ 2024-02-15 5712/week @ 2024-02-22 5906/week @ 2024-02-29 4272/week @ 2024-03-07

22,742 downloads per month
Used in 263 crates (53 directly)

MIT license

17KB
326 lines

TypeMap

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

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

#[deriving(Show, PartialEq)]
struct KeyType;

#[deriving(Show, PartialEq)]
struct Value(i32);

impl Key for KeyType { type Value = Value; }

#[test] fn test_pairing() {
    let mut map = TypeMap::new();
    map.insert::<KeyType>(Value(12));
    assert_eq!(*map.find::<KeyType>().unwrap(), Value(12);
}

lib.rs:

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

Dependencies

~13KB