Crate anygma

Source
Expand description

This crate makes it easy to define arrays containing different types.

§Examples

use anygma::ary_anyref;

let a = ary_anyref![0, 'a', "str"];
assert_eq!(a[0].downcast_ref::<i32>(), Some(&0));
assert_eq!(a[1].downcast_ref::<char>(), Some(&'a'));
assert_eq!(a[2].downcast_ref::<&str>(), Some(&"str"));
use anygma::ary_tref;

let a = ary_tref![&dyn std::fmt::Debug; 0, 'a', "str"];
println!("{:?}", a);

You can also create your own new macros using ary_tref!

macro_rules! ary_debug {
    ( $( $value:expr ),+ $(,)? ) => {
        ary_tref![&dyn std::fmt::Debug; $($value),+]
    };
}

let a = ary_debug![0, 'a', "str"];
println!("{:?}", a);

Macros§

ary_anybox
This macro is a convenient way to create an array of Any trait objects.
ary_anyref
This macro is a convenient way to create an array of Any trait objects.
ary_tbox
This macro is a convenient way to create arrays of trait objects that you specify.
ary_tref
This macro is a convenient way to create arrays of trait objects that you specify.