1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#1833 in Database interfaces

Download history 21454/week @ 2024-01-02 23621/week @ 2024-01-09 24754/week @ 2024-01-16 25937/week @ 2024-01-23 30085/week @ 2024-01-30 30936/week @ 2024-02-06 29761/week @ 2024-02-13 33426/week @ 2024-02-20 32161/week @ 2024-02-27 36155/week @ 2024-03-05 38891/week @ 2024-03-12 34927/week @ 2024-03-19 34033/week @ 2024-03-26 33738/week @ 2024-04-02 35529/week @ 2024-04-09 32852/week @ 2024-04-16

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