1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#2477 in Database interfaces

Download history 45802/week @ 2024-11-30 45688/week @ 2024-12-07 47285/week @ 2024-12-14 48805/week @ 2024-12-21 35939/week @ 2024-12-28 55065/week @ 2025-01-04 51154/week @ 2025-01-11 52191/week @ 2025-01-18 48107/week @ 2025-01-25 48777/week @ 2025-02-01 65758/week @ 2025-02-08 65436/week @ 2025-02-15 74462/week @ 2025-02-22 77727/week @ 2025-03-01 81855/week @ 2025-03-08 66625/week @ 2025-03-15

312,520 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