#macro #utility #array #containing #define #different #type

anygma

anygma makes it easy to define arrays containing different types

1 unstable release

0.1.0 Feb 4, 2024

#2987 in Rust patterns

MIT/Apache

8KB
113 lines

anygma 🦝

Actions Status Crates.io Documentation

anygma 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"));

Contributing

This project welcomes your PR and issues. For example, fixing bugs, adding features, refactoring, etc.


lib.rs:

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);

No runtime deps