For those interested, this is my current approach, simple, automatic, easy to maintain and improve (haven't test it yet, but I will follow this approach):
#[macro_export]
macro_rules! arr_from_consts {
($nv:vis const $ni:ident = [$( $(#[doc = $doc:expr])* $v:vis const $i:ident: $t:ty = $e:expr; )*]) => {
$($v const $i: $t = $e;)*
$nv const $ni: [&str; count!($($i)*)] = [
$($i),*
];
}
}
And can be used like so:
arr_from_consts!(
pub const MyConstants = [
pub const MyConstant1: &str = "Hello";
pub const MyConstant2: &str = "Stackoverflow";
]);
Thanks to everyone.
Edit: The count macro:
macro_rules! count {
() => (0usize);
( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*));
}
From this link, for example.