Skip to content

Query's ExactSizeIterator does not account for partial iteration #5149

Closed
@alice-i-cecile

Description

@alice-i-cecile

Bevy version

0.8-dev

Problem

The [ExactSizeIterator] docs imply that the value returned by len() should change as the iterator is partially consumed.

Our implementations do not do this.

We should carefully check to ensure that our size_hint methods are correct too.

Possible solutions

Solution 1: track directly

This solution solves the problem at hand, but creates unavoidable overhead in cases where we don't care.

Solution 2: create a ExactSizeQueryIter type

Only implement the ExactSizeIterator trait for this type.

Avoids overhead, gains the correct behavior, but ergonomics are a bit meh.
If we do this, this must be documented carefully.

Solution 3: scrap the ExactSizeIterator trait, and implement len() directly

This is a bit sad, because it reduces compatibility with other ecosystem crates that care about this trait.

Solution 4: YOLO

Keep the current behavior that does not comply with the spec. The docs do say you can't rely on this for soundness...

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions