https://github.com/reem/rust-typemap
A typesafe store keyed by types and containing different types of values.
https://github.com/reem/rust-typemap
Last synced: 25 days ago
JSON representation
A typesafe store keyed by types and containing different types of values.
- Host: GitHub
- URL: https://github.com/reem/rust-typemap
- Owner: reem
- Created: 2014-08-19T09:01:18.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-12-27T14:45:13.000Z (over 6 years ago)
- Last Synced: 2024-03-04T13:33:17.120Z (about 1 year ago)
- Language: Rust
- Homepage:
- Size: 53.7 KB
- Stars: 170
- Watchers: 8
- Forks: 30
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# `TypeMap`
> A typesafe store keyed by types and containing different types of values.
## [Documentation](https://crates.fyi/crates/typemap/0.3.3)
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
```rust
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::(Value(42));
assert_eq!(*map.get::().unwrap(), Value(42));
}
```