bevy icon indicating copy to clipboard operation
bevy copied to clipboard

refactor: move internals from `entity_ref` to storages, add `SAFETY` comments

Open jakobhellermann opened this issue 2 years ago • 3 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 Storages and make them public
  • move take_component to Storages
  • replace pub use entity_ref::*; with pub use entity_ref::{EntityRef, EntityMut} and qualified entity_ref::get_mut[_by_id] in world.rs
  • add safety comments to a bunch of methods

jakobhellermann avatar Oct 29 '22 09:10 jakobhellermann

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.

jakobhellermann avatar Oct 29 '22 09:10 jakobhellermann

I agree with the code reorg. Lemme take a look at the safety comments...

alice-i-cecile avatar Oct 29 '22 22:10 alice-i-cecile

Rebased and pushed a few commits cleaning up the comments.

jakobhellermann avatar Nov 15 '22 19:11 jakobhellermann

Rebased and addressed the comments (only https://github.com/bevyengine/bevy/pull/6402#discussion_r1069484597 pending)

jakobhellermann avatar Jan 13 '23 13:01 jakobhellermann

I updated the PR description

jakobhellermann avatar Jan 13 '23 16:01 jakobhellermann

bors r+

alice-i-cecile avatar Jan 13 '23 16:01 alice-i-cecile