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

#10 in #keyed

Download history 19769/week @ 2024-07-20 19481/week @ 2024-07-27 21351/week @ 2024-08-03 21765/week @ 2024-08-10 19768/week @ 2024-08-17 17478/week @ 2024-08-24 18155/week @ 2024-08-31 17904/week @ 2024-09-07 18856/week @ 2024-09-14 20644/week @ 2024-09-21 19340/week @ 2024-09-28 20815/week @ 2024-10-05 18889/week @ 2024-10-12 19003/week @ 2024-10-19 15902/week @ 2024-10-26 15705/week @ 2024-11-02

71,902 downloads per month
Used in 257 crates (52 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