Crate typemap_core[][src]

A no_std typemap with trait-based value-presence guarantees (on nightly)

aka: A map from a type to a value of that type, without needing std/alloc

Example

use typemap_core::{typemap, Contains, TypeMapGet};

fn uses_options<Opts: Contains<&'static str> + Contains<u32>>(opts: &Opts) {
    println!("str: \"{}\", u32: {}", opts.get::<&str>(), opts.get::<u32>());
}

let options = typemap!(u128 = 34u128, &str = "Hello, world!", u32 = 45u32);
uses_options(&options);

Nightly

Nightly is not required to use this library, but it is reccomended to at least check your code on nightly occasionally given the nature of the Contains<T> and ContainsMut<T> traits. On nightly, these traits ensure that you can only call the methods that panic when they are guaranteed not to panic. On stable, we can't implement it properly, so it merely has a blanket impl so that your trait bounds setup for nightly do not cause issues on stable.

Macros

typemap

Helper for creating a value of a typemap.

typemap_ty

Helper for expressing the type of a typemap.

Structs

Ty

A type-level linked-list implementation of a typemap

TyEnd

The end of a typemap.

Traits

Contains

The Contains trait marks a map as containing at least one instance of a given type that can be accessed

ContainsMut

The ContainsMut trait marks a map as containing at least one instance of a given type that can be mutated

TypeMapGet

The TypeMapGet trait allows for obtaining values of types from a typemap.

TypeMapSet

The TypeMapSet trait allows for setting values of types in a typemap.