Ralith / hecs

A handy ECS
Apache License 2.0
967 stars 82 forks source link

hecs::Query should handle type parameters #359

Open sanbox-irl opened 9 months ago

sanbox-irl commented 9 months ago

Basically I'd love this to work:

#[derive(hecs::Query)]
pub struct DrawSpriteQuery<'a, SpriteLike = Sprite> {
    pub transform: &'a Transform,
    pub sprite: &'a SpriteLike,
    pub shader_routine: &'a crate::gfx::ShaderRoutine,
    pub size: Option<&'a Size>,
}

I'll take a look in the macro to see how tough it would be, but I suspect not terribly difficult, but not sure!

Ralith commented 9 months ago

The easy and composable thing would be to assume all type parameters are Querys and do <'a, SpriteLike = &'a Sprite> and pub sprite: SpriteLike. The general case, including your example as written, probably requires allowing the user to specify custom bounds.

Ralith commented 9 months ago

On second thought, if we just pass through the bounds specified on the type, we can probably handle all cases gracefully.