bevy/crates/bevy_winit/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
..
accessibility.rs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00
converters.rs Expose text field from winit in KeyboardInput (#16864) 2024-12-17 22:42:54 +00:00
cursor.rs Move CustomCursor to bevy_winit/src/custom_cursor.rs (#17381) 2025-01-15 05:35:57 +00:00
custom_cursor.rs Move CustomCursor to bevy_winit/src/custom_cursor.rs (#17381) 2025-01-15 05:35:57 +00:00
lib.rs Move #![warn(clippy::allow_attributes, clippy::allow_attributes_without_reason)] to the workspace Cargo.toml (#17374) 2025-01-15 01:14:58 +00:00
state.rs Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
system.rs Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
winit_config.rs Remove everything except Instant from bevy_utils::time (#17158) 2025-01-05 20:36:08 +00:00
winit_monitors.rs Simpler lint fixes: makes ci lints work but disables a lint for now (#15376) 2024-09-24 11:42:59 +00:00
winit_windows.rs Support non-Vec data structures in relations (#17447) 2025-01-20 21:26:08 +00:00