1 stable release

Uses old Rust 2015

1.0.0 Sep 3, 2022

#702 in Rust patterns

Download history 6743/week @ 2022-10-14 8723/week @ 2022-10-21 8776/week @ 2022-10-28 9807/week @ 2022-11-04 9350/week @ 2022-11-11 9182/week @ 2022-11-18 10141/week @ 2022-11-25 10295/week @ 2022-12-02 10285/week @ 2022-12-09 11601/week @ 2022-12-16 6690/week @ 2022-12-23 9128/week @ 2022-12-30 13436/week @ 2023-01-06 12271/week @ 2023-01-13 12524/week @ 2023-01-20 11128/week @ 2023-01-27

51,675 downloads per month
Used in 4 crates (via log4rs)

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

~14KB