Expand description
A simple compile-time derive macro to create type-to-value maps.
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.
§Example
#[derive(Typemap)]
struct Test(i32, f32);
let t = Test(1, 2.0);
assert_eq!(*get!(t, i32), 1);
assert_eq!(*get!(t, f32), 2.0);To get mutable references, add the #[typemap_mut] attribute on your struct, and
use get_mut! instead of get!:
#[derive(Typemap)]
#[typemap_mut]
struct Test(i32, f32);
let mut t = Test(1, 2.0);
assert_eq!(*get!(t, i32), 1);
assert_eq!(*get!(t, f32), 2.0);
*get_mut!(t, i32) = 3;
*get_mut!(t, f32) = 4.0;
assert_eq!(*get!(t, i32), 3);
assert_eq!(*get!(t, f32), 4.0);Macros§
- get
- Convenience macro to get a specific type
$tfrom a tuple struct$scontaining disjoint heterogeneous types - get_mut
- Convenience macro to mutably get a specific type
$tfrom a tuple struct$scontaining disjoint heterogeneous types
Traits§
- Get
- Helper trait to get a specific type
Tfrom a tuple struct containing disjoint heterogeneous types - GetMut
- Helper trait to mutably get a specific type
Tfrom a tuple struct containing disjoint heterogeneous types
Derive Macros§
- Typemap
- Add static type-to-value getters to a tuple struct containing disjoint heterogeneous types