#Getting the parameter index from all_tuples!

15 messages · Page 1 of 1 (latest)

craggy hull
#

I want to collect all the members of the tuple like so:

Vec::from([self.0.into(), self.1.into(), self.2.into()])

However, I can't figure out how to do this with Bevy's all_tuples macro. Other tuple macro crates such as impl_trait_for_tuples and fortuples have this ability.

abstract forge
#

what have you tried?

#

should be possible with a trait used to push tuple items to a vec

craggy hull
#

With the other crates, you can just get the tuple index.

abstract forge
#

yeah use your own trait, with your own impl being replicated by the macro

#

that impl could well be vec.push(tup.$n.into())

#

or something

craggy hull
#

Here's what I have - this doesn't work because $T is T0, not 0:

macro_rules! impl_class_names {
    ($($T:ident),*) => {
        impl<$($T: ConditionalClassName),*> ClassNamesTuple for ($($T,)*) {
            fn to_vec(self) -> Vec<Option<String>> {
                Vec::from([$(self.$T.to_class()),* ])
            }
        }
    };
}
#

With impl_trait_for_tuples if you say self.T it knows you want an index, not a type name.

abstract forge
#

ah hmm

craggy hull
#

I'm using that package now, but I wanted to migrate to the bevy solution and reduce my dependencies.

abstract forge
#

yeah looking at how its used in bevy i think its meant as a type system only thing?

craggy hull
#

Hmmm, ok

abstract forge
#

mainly used to act on types, like in queries, bundles, etc