What the turbofish

29 points grrumblebee

I'm an experienced programmer but rust newbie, and I'm learning the language from Hands-on Rust: Effective Learning through 2D Game Development and Play, which I recommend.

While the book does its best to teach rust from scratch and teach you how to make simple, roguelike games, it can only go into so much depth about complex rust features, so I augment it by googling anything I don't understand. So far, this has worked, until, on page 113, it explained how to use an ECS system (called legion) with this expression:

<(Point, MeleeAI)>::query()

Here, my googlefu failed me. The author mentions that this is a turbofish. There's very little online about turbofish. The few links I've found seem to be high-level discussions from people who already understand them. And none of the turbofish examples I find look quite like this, e.g. with a tuple inside them.

I think I understand all the bits and pieces of this expression. I know angle-brackets are used to surround generics; I know that the item inside the brackets is a tuple; I know the whole expression is a path expression, and, clearly, it's calling a function. But I'm not sure how all those parts are working together. It's the only example I've seen of a tuple inside angle brackets, except for a few with "as" casting inside them, which this doesn't have.

I'm guessing Point and MeleeAI are types or structs or objects with traits and, somehow, either of them have a query function. Or something like that. But I've been pouring over online books, message boards, youtube videos, stack overflow, etc. without seeing anything like this. I'm not even sure what to search.

I really want to understand this, because it looks like it's packing a lot of interesting rust features in a small expression.