#Unpack Query into a struct?

10 messages ยท Page 1 of 1 (latest)

storm ridge
#

What I'd like to do is...

Instead of

fn system(query: Query<(&A, &B)>) {
    ...
    for (a, b) in query.iter {
    ...
}

I would like to

fn system(query: Query<&MyStructType>) {
    ...
    for MyStructType{ a, b } in query.iter {
    ...
}

I'll happily elaborate if it helps.

I believe I want my type to implement WorldQuery but it looks like there are many ways to get lost in this code. I could cheat and make the type's ::new() function take a tuple, but that seems yuck and would add another line. ๐Ÿ˜•

#

Interesting. "But you can", you say.

#

I mean, I've done it tons. Let me think and make sure I didn't just play myself....

#

Yeah. Heh. NEVERMIND! I guess it's just a slightly new application in my case and my brain hiccuped. Thanks anyhow ! ๐Ÿ™‚

rustic cloud
#

Have you seen the WorldQuery derive?

storm ridge
#

nope. I'll check it out. But IINM I got what I need.

rustic cloud
#

Please don't try and impl it by hand unless you have a very good reason :p

storm ridge
#

well, example number two above will work. It's nothing special. maybe I'm doubly confused.

#

the elements of MyStructType will be Transform ... the usual suspects. My components in some cases.

#

If I'll get tangled up I'll post back. I will definitely look into derive WQ as it'll probably resolve the current confusion (and more). Thanks @rustic cloud !