1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#1827 in Database interfaces

Download history 31920/week @ 2023-12-06 26384/week @ 2023-12-13 17825/week @ 2023-12-20 14862/week @ 2023-12-27 22314/week @ 2024-01-03 23731/week @ 2024-01-10 25339/week @ 2024-01-17 26099/week @ 2024-01-24 30749/week @ 2024-01-31 30312/week @ 2024-02-07 30297/week @ 2024-02-14 32905/week @ 2024-02-21 33745/week @ 2024-02-28 36583/week @ 2024-03-06 38038/week @ 2024-03-13 28853/week @ 2024-03-20

142,449 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