Safe version of `BundleScratch`/`BundleWriter`
C-FeatureA-ECSS-Ready-For-ImplementationD-Unsafe
## What problem does this solve or what need does it fill?
There are times when you want to conditionally/dynamically insert components based on runtime values. Typically this would require you to use `Commands::insert`, which would trigger an archetype move. This is usually bad for performance.
[`BundleScratch`](https://docs.rs/bevy/latest/bevy/ecs/bundle/struct.BundleScratch.html) and [`BundleWriter`](https://docs.rs/bevy/latest/bevy/ecs/bundle/struct.BundleWriter.html) solves this problem by letting you push components into a temporary scratch space, before applying them to an entity [all at once](https://github.com/bevyengine/bevy/blob/7b2b90997ae2e73558ace09cc065d31a2c24b266/crates/bevy_ecs/src/bundle/writer.rs#L186-L204).
But unfortunately, they both currently require `unsafe` to operate. It should be possible to automatically uphold the invariants that these types demand via an abstraction.
## What solution would you like?
Provide a safe abstraction for `BundleScratch` and `BundleWriter`, so that users could benefit from them without using `unsafe`.
## What alternative(s) have you considered?
Continue using `unsafe` in order to use `BundleScratch` and `BundleWriter`.
0 条评论