Rust typemaps with additional trait restrictions and implementations
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trivernis bdb5145fdb
Add typemap that is Send + Sync without being Clone
Signed-off-by: trivernis <>
1 year ago
src Add typemap that is Send + Sync without being Clone 1 year ago
.gitignore Add initial map implementations 1 year ago
Cargo.toml Add typemap that is Send + Sync without being Clone 1 year ago
LICENSE Create LICENSE 1 year ago Rename TypeMapTrait to TypeMap 1 year ago

Trait bound Typemap

This crate offers typemaps that restrict a given type in their trait and therefore offer additional trait implementations such as Clone and PartialEq.


This crate relies on the multi-trait-object crate which provides a workaround for storing a type erased object with all associated traits until this feature is implemented in the language itself. This crate will likely break when the fat pointer used by trait objects changes which it hasn't in a long time so far.


use trait_bound_typemap::{CloneTypeMap, AnyTypeMap, TypeMap, TypeMapKey};

pub struct MyStruct {
    a: u8,
    b: String,

pub struct MyStructKey;

impl TypeMapKey for MyStructKey {
    type Value = MyStruct;

fn main() {
    let mut map = CloneTypeMap::new();
    let value = MyStruct {a: 5, b: String::from("Hello World")};

    // can be cloned
    let map2 = map.clone();

    // less restrictive is always allowed
    let any_map = AnyTypeMap::from_iter(map2);