Skip to content
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

Relax BufferVec's type constraints #12866

Merged
merged 2 commits into from
Apr 5, 2024

Conversation

james7132
Copy link
Member

@james7132 james7132 commented Apr 3, 2024

Objective

Since BufferVec was first introduced, bytemuck has added additional traits with fewer restrictions than Pod. Within BufferVec, we only rely on the constraints of bytemuck::cast_slice to a u8 slice, which now only requires T: NoUninit which is a strict superset of Pod types.

Solution

Change out the Pod generic type constraint with NoUninit. Also taking the opportunity to substitute cast_slice with must_cast_slice, which avoids a runtime panic in place of a compile time failure if T cannot be used.


Changelog

Changed: BufferVec now supports working with types containing NoUninit but not Pod members.
Changed: BufferVec will now fail to compile if used with a type that cannot be safely read from. Most notably, this includes ZSTs, which would previously always panic at runtime.

@james7132 james7132 added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use labels Apr 3, 2024
@james7132 james7132 requested review from JMS55 and pcwalton April 3, 2024 21:49
Copy link
Contributor

@msvbg msvbg left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@pcwalton pcwalton left a comment

Choose a reason for hiding this comment

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

LGTM

@james7132 james7132 enabled auto-merge April 5, 2024 02:01
@james7132 james7132 added this pull request to the merge queue Apr 5, 2024
Merged via the queue into bevyengine:main with commit a4ed1b8 Apr 5, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants