typemap-meta
Overview
A simple compile-time (hence the meta) derive macro to create type-to-value maps (hence the typemap).
This approach in contrast to crates such as typemap
or type-map
that perform run-time lookup.
The static typing brings compile-time safety and faster execution at the expense of using a derive macro and generics.
The crate is no_std
compatible.
Usage
To use this crate, first add this to your Cargo.toml
:
[]
= "0.2"
Then, you can create a tuple struct containing disjoint heterogeneous types, and derive Typemap
, and then use the get!
macro (a syntactic sugar around Typemap::Get
):
;
let t = Test;
assert_eq!;
assert_eq!;
A mutable version is also available:
;
let mut t = Test;
*get_mut! = 3;
*get_mut! = 4.0;
assert_eq!;
assert_eq!;
Crate structure
As currently procedural macros must be defined in their own crate, we have two crates typemap-meta
and typemap-meta-derive
, the former re-exporting the macro from the later.
Only the former needs to be imported in your project.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.