-
-
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
Component: Sync
(might be) too strict.
#2487
Comments
So we've done a review of uses of |
I would be happy to see a PR tackling this: I think that weakening trait bounds like this is generally good hygiene. |
I've run into this using a linear type pattern for a state machine. The statemachine API doesn't really support borrows. Everything is moved. When integrating with bevy, I realized the state machine needs to implement sync (send is still logical) but doesn't. So I either need to change my data structure to make bevy happy, or put it in a mutex to make bevy happy :). |
In your case, bevy main has |
This is partially addressed via #6864, which makes it a user-facing problem instead of one solved by bevy_ecs itself. Though it forces mutable access which may not be conducive to UX, especially regarding change detection. |
I agree that this is a capability we can get from composability. |
What problem does this solve or what need does it fill?
Our requirements are too strict. This stops us from using types which are
Send
but notSync
in components, such asCell<T>
.What solution would you like?
Remove the bound of
Sync
on component, and audit all the methods ofWorld
to ensure that any which go from&World->&T
requireT: Sync
(primarily theSystemParam
impl for&'_ T
).Note that the impl for
&'_ mut T
would not requireSync
, since we guarantee that this reference is only on one thread (since the resultantMut<T>
can be used to get an&mut T
directly).What alternative(s) have you considered?
Keep things as they are - we haven't had a need for this yet, and it seems unlikely that we ever will.
However, philosophically there's no reason to have these bounds, and it strictly increases our usefulness.
Additional context
https://doc.rust-lang.org/nomicon/send-and-sync.html
https://doc.rust-lang.org/std/marker/trait.Sync.html
The text was updated successfully, but these errors were encountered: