-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add an API for accessing world storages from UnsafeWorldCell
#8280
Conversation
crates/bevy_ecs/src/storage/mod.rs
Outdated
/// Accessing world data that do not have access to, or mutably accessing | ||
/// data that you only have read-access to, is considered undefined behavior. | ||
pub struct UnsafeStorages<'a> { | ||
pub sparse_sets: UnsafeSparseSets<'a>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docs on these fields.
@@ -41,3 +43,71 @@ pub struct Storages { | |||
/// Backing storage for `!Send` resources. | |||
pub non_send_resources: Resources<false>, | |||
} | |||
|
|||
/// Provides interior-mutable access to a world's internal data storages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should link to the critical concepts here. "interior mutability" and "undefined behavior" would be very nice to link out to for newcomers to Rust who run into this in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I imagine the rustonomicon will be a good starting point, but let me know if there are other resources you think would be worth including here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overarching docs feedback:
- We should link to [
Ticks
] where referenced in the docs: this is very jargon. - We need to explain why the
Option
that we return from most of this APIs could be None.
Do we have a usecase for non- |
I was planning on removing/hiding those APIs in a follow-up, if it seems like a good idea after migrating the engine. For now, I want this PR to be non-breaking. |
Hm, I think if you plan to do it anyways, doing it now would unnecessary work for you, and we wouldn't need to review twice. Once for this PR, then again for moving the |
I've been thinking about this off and on, and I think that a good way of handling this API would be:
This would make Thoughts? |
After even more thought, I don't think this PR is the right direction. |
Objective
Re-do of #8175.
UnsafeWorldCell
is a type that provides interior mutable access to a world. Currently, the only way to access world data is through high-level methods. In order to makeUnsafeWorldCell
a full replacement for the interior-mutable-ish version of&World
, we need a way of accessing the world's internal data storages.Solution
Provide an API for accessing a world's internal data stores via
UnsafeWorldCell
. World accesses are gated behind unsafe, with the unsafe code deferred as late as possible to encourage clean code.Changelog
UnsafeStorages
API, for interior mutable access to a World's internal data stores viaUnsafeWorldCell
.Future Work
Use this API in the engine. In particular, it will be useful when porting
Query
andWorldQuery
over to usingUnsafeWorldCell
.