#typemap #anymap

typemap

A typesafe store for many value types

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
Download history 8576/week @ 2020-12-25 13757/week @ 2021-01-01 15186/week @ 2021-01-08 14201/week @ 2021-01-15 16753/week @ 2021-01-22 18363/week @ 2021-01-29 17608/week @ 2021-02-05 17611/week @ 2021-02-12 16074/week @ 2021-02-19 20090/week @ 2021-02-26 18298/week @ 2021-03-05 15865/week @ 2021-03-12 16153/week @ 2021-03-19 15925/week @ 2021-03-26 16553/week @ 2021-04-02 13895/week @ 2021-04-09

66,199 downloads per month
Used in 244 crates (46 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