bevy
bevy copied to clipboard
refactor: move internals from `entity_ref` to storages, add `SAFETY` comments
Objective
There are some utility functions for actually working with Storages inside entity_ref.rs that are used both for EntityRef/EntityMut and World, with a // TODO: move to Storages.
This PR moves them to storages so that entity_ref.rs gets easier to read, working with Storages becomes easier and world.rs doesn't import as much from entity_ref.rs.
Solution
- move get_component[_with_type], get_ticks[_with_type], get_component_and_ticks[_with_type] to
Storagesand make them public - move
take_componenttoStorages - replace
pub use entity_ref::*;withpub use entity_ref::{EntityRef, EntityMut}and qualifiedentity_ref::get_mut[_by_id]inworld.rs - add safety comments to a bunch of methods
CI will get fixed in 4 days with 1.65: https://github.com/rust-lang/rust/pull/100081
If this should be merged before, I can remove the unsafe blocks.
I agree with the code reorg. Lemme take a look at the safety comments...
Rebased and pushed a few commits cleaning up the comments.
Rebased and addressed the comments (only https://github.com/bevyengine/bevy/pull/6402#discussion_r1069484597 pending)
I updated the PR description
bors r+
Pull request successfully merged into main.
Build succeeded:
- build-and-install-on-iOS
- build-android
- build (macos-latest)
- build (ubuntu-latest)
- build-wasm
- build (windows-latest)
- build-without-default-features (bevy)
- build-without-default-features (bevy_ecs)
- build-without-default-features (bevy_reflect)
- check-compiles
- check-doc
- check-missing-examples-in-docs
- ci
- markdownlint
- msrv
- run-examples
- run-examples-on-wasm
- run-examples-on-windows-dx12