Skip to content

Cast query of mutable components to query of immutable #4606

@michalmoc

Description

@michalmoc

Because of Rust borrow checker I'm usually forced to pass around entities and queries. But there seems to be a problem when I've got a mutable query but it suffices to have immutable one, like

fn some_function(entities: &Vec<Entity>, query: &Query<&SomeComponent>){...}

fn some_system(some_entities: Res<Vec<Entity>>, query: Query<&mut SomeComponent>)
{
    for mut c in query.iter_mut() {...};

    some_function(some_entities, query);
}

As far as I can see there is no way to cast the query although it seems reasonable to do so. I believe there should exist some implementation of AsRef trait or perhaps some new trait like CanQuery<ComponentType>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to use

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions