I'd like to store a list of types somehow, so that I can use those types as arguments to a macro. For instance:
macro_rules! component_types {
() => {
AreaOfEffect,
BlocksTile,
CombatStats,
Confusion,
Consumable,
EventIncomingDamage,
EventWantsToDropItem,
EventWantsToMelee,
EventWantsToPickupItem,
EventWantsToUseItem,
InBackpack,
InflictsDamage,
Item,
Monster,
Name,
Player,
Position,
ProvidesHealing,
Ranged,
Renderable,
SerializationHelper,
Viewshed,
};
}
Then these could be used by this macro (not my work):
macro_rules! serialize_individually {
($ecs:expr, $ser:expr, $data:expr, $( $type:ty),*) => {
$(
SerializeComponents::<NoError, SimpleMarker<SerializeMe>>::serialize(
&( $ecs.read_storage::<$type>(), ),
&$data.0,
&$data.1,
&mut $ser,
)
.unwrap();
)*
};
}
I imagine usage could look like this:
serialize_individually!(ecs, serializer, data, component_types!());
However, when I do this, I get:
error: macro expansion ignores token `,` and any following
--> src/saveload_system.rs:45:19
|
45 | AreaOfEffect,
| ^
...
177 | serialize_individually!(ecs, serializer, data, component_types!());
| ------------------ caused by the macro expansion here
|
= note: the usage of `component_types!` is likely invalid in type context
I've tried to think about how to do this using tuples and HLists from other libraries, but haven't hit on anything yet. Is there any possible way to do this, short of bringing in an external macro system like m4?