add a QueryManyUniqueIter
Objective
~Requires #13476~.
Currently we cannot iterate mutably over QueryManyIter even if all entities we pass are unique.
Solution
Add a QueryManyUniqueIter wrapper around QueryManyIter for full Iterator trait iteration.
It can be constructed via either the dedup_entities or entities_all_unique method on QueryManyIter.
dedup_entities deduplicates the internal entity_iter, retaining order.
entities_all_unique takes self, checks for uniqueness, returns QueryManyUniqueIter on success, and QueryManyIter (Self) on failure.
Since QueryManyUniqueIter can iterate over mutable QueryData , it does not expose a fetch_next method.
Testing
The example/doc test shows the method in use, also making sure expect can be called on the return Result.
Changelog
Added dedup_entities and entities_all_unique methods on QueryManyIter.
Added QueryManyUniqueIter struct.
I wonder whether it might be easier to have a direct Query::iter_many_unique method instead of these roundabout conversions on QueryManyIter.
I have come up with a more powerful, general solution, which I think I will put in a different PR. I'll keep this open as the simpler alternative.
~~This PR would also need to be updated with a TrustedEq: Eq trait, because even though we only use it for Entity, unsafe code must not rely on an Eq trait impl for correctness, because Eq itself does not contain a logical correctness guarantee.
That being said, this would be a simple unsafe marker trait impl on Entity stating the safety contract.~~
This PR is now superseded by the concept of #16547, though the actual conversion API would be a follow-up to that PR.
#16547 has merged.