bevy/crates/bevy_ui/src
Alice Cecile 5a9bc28502
Support non-Vec data structures in relations (#17447)
# Objective

The existing `RelationshipSourceCollection` uses `Vec` as the only
possible backing for our relationships. While a reasonable choice,
benchmarking use cases might reveal that a different data type is better
or faster.

For example:

- Not all relationships require a stable ordering between the
relationship sources (i.e. children). In cases where we a) have many
such relations and b) don't care about the ordering between them, a hash
set is likely a better datastructure than a `Vec`.
- The number of children-like entities may be small on average, and a
`smallvec` may be faster

## Solution

- Implement `RelationshipSourceCollection` for `EntityHashSet`, our
custom entity-optimized `HashSet`.
-~~Implement `DoubleEndedIterator` for `EntityHashSet` to make things
compile.~~
   -  This implementation was cursed and very surprising.
- Instead, by moving the iterator type on `RelationshipSourceCollection`
from an erased RPTIT to an explicit associated type we can add a trait
bound on the offending methods!
- Implement `RelationshipSourceCollection` for `SmallVec`

## Testing

I've added a pair of new tests to make sure this pattern compiles
successfully in practice!

## Migration Guide

`EntityHashSet` and `EntityHashMap` are no longer re-exported in
`bevy_ecs::entity` directly. If you were not using `bevy_ecs` / `bevy`'s
`prelude`, you can access them through their now-public modules,
`hash_set` and `hash_map` instead.

## Notes to reviewers

The `EntityHashSet::Iter` type needs to be public for this impl to be
allowed. I initially renamed it to something that wasn't ambiguous and
re-exported it, but as @Victoronz pointed out, that was somewhat
unidiomatic.

In
1a8564898f,
I instead made the `entity_hash_set` public (and its `entity_hash_set`)
sister public, and removed the re-export. I prefer this design (give me
module docs please), but it leads to a lot of churn in this PR.

Let me know which you'd prefer, and if you'd like me to split that
change out into its own micro PR.
2025-01-20 21:26:08 +00:00
..
experimental Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
layout Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
render Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
widget Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
accessibility.rs Properly set accessible value on label nodes (#16418) 2024-11-17 18:10:41 +00:00
focus.rs Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00
geometry.rs Implement FromStr for Val (#16926) 2024-12-24 02:51:13 +00:00
lib.rs Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00
measurement.rs Use CosmicFontSystem in public bevy_text APIs and remove cosmic_text re-export (#16063) 2024-10-23 20:05:28 +00:00
picking_backend.rs Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00
stack.rs Relationships (non-fragmenting, one-to-many) (#17398) 2025-01-18 22:20:30 +00:00
ui_material.rs bevy_ui: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17229) 2025-01-08 19:30:19 +00:00
ui_node.rs Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00
update.rs Rename TargetCamera to UiTargetCamera (#17403) 2025-01-19 19:56:57 +00:00