Skip to content

wrap EntityIndexMap/Set slices as well #18134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Victoronz
Copy link
Contributor

@Victoronz Victoronz commented Mar 3, 2025

Objective

Continuation of #17449.

#17449 implemented the wrapper types around IndexMap/Set and co., however punted on the slice types.
They are needed to support creating EntitySetIterators from their slices, not just the base maps and sets.

Solution

Add the wrappers, in the same vein as #17449 and #17589 before.

The Index/IndexMut implementations take up a lot of space, however they cannot be merged because we'd then get overlaps.

They are simply named Slice to match the indexmap naming scheme, but this means they cannot be differentiated properly until their modules are made public, which is already a follow-up mentioned in #17954.

@Victoronz Victoronz added A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Unsafe Touches with unsafe code in some way S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 3, 2025
@@ -197,6 +351,471 @@ where

impl<V: Eq> Eq for EntityIndexMap<V> {}

pub struct Slice<V, S = EntityHash>(PhantomData<S>, map::Slice<Entity, V>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need the S parameter here (and in index_set::Slice)? I don't see any impls that use anything other than the default, so I don't think these can be created or used with any other type parameter.

Copy link
Contributor Author

@Victoronz Victoronz Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same as with the iterator types: Technically not needed yet, but without it, the type alone doesn't convey why it exists!

Later on, when more trusted combinations of Hasher and Hash are introduced (MainEntity + EntityHash f.e.), this generic can carry proper semantic meaning.

}
}

impl<V: PartialOrd> PartialOrd for Slice<V> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you #[derive(PartialOrd, Ord, PartialEq, Eq, Hash)] for these? (And similarly for index_set::Slice)

Copy link
Contributor Author

@Victoronz Victoronz Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because of the S parameter, a derive would require that generic to implement these traits as well.
The functionality needed to derive here is called "perfect derive".

@Victoronz Victoronz added this to the 0.16 milestone Mar 10, 2025
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Mar 17, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 17, 2025
Merged via the queue into bevyengine:main with commit d229475 Mar 17, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Unsafe Touches with unsafe code in some way S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants