-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - yeet World::components_mut
>:(
#4092
Conversation
Maybe return a |
|
We require |
Moving out is fine, its mutating the |
If you move something out of a mutable reference, you have to move something else in which is a non appending mutation. |
Looking at what methods are on
additionally all fields are private, so I think there is not any harm in just removing |
Oh nevermind |
If this is the case, would it be worth privating those APIs too, since there will be no way to reasonably use those from the World API with this removed? |
bors r+ |
# Objective make bevy ecs a lil bit less unsound ## Solution yeet unsound API `World::components_mut`: ```rust use bevy_ecs::prelude::*; #[derive(Component)] struct Foo(u8); #[derive(Debug, Component)] struct Bar([u8; 100]); fn main() { let mut world = World::new(); let e = world.spawn().insert(Foo(0)).id(); *world.components_mut() = Default::default(); let bar = world.entity_mut(e).remove::<Bar>().unwrap(); // oopsies reading memory copied from outside allocation dbg!(bar); } ```
This seems like a reasonable fix for this specific instance of the problem, but I am a little concerned about what this "issue" means for Rust api design. Pasting in some of my thoughts from Discord:
@BoxyUwU then brought up this solution:
Boxy's solution is definitely a "real" solution, but its definitely not "ideal" from an implementation or documentation perspective because it adds real implementation complexity / makes it so you can't talk about Components as a simple "read / write collection" anymore. |
World::components_mut
>:(World::components_mut
>:(
# Objective make bevy ecs a lil bit less unsound ## Solution yeet unsound API `World::components_mut`: ```rust use bevy_ecs::prelude::*; #[derive(Component)] struct Foo(u8); #[derive(Debug, Component)] struct Bar([u8; 100]); fn main() { let mut world = World::new(); let e = world.spawn().insert(Foo(0)).id(); *world.components_mut() = Default::default(); let bar = world.entity_mut(e).remove::<Bar>().unwrap(); // oopsies reading memory copied from outside allocation dbg!(bar); } ```
# Objective make bevy ecs a lil bit less unsound ## Solution yeet unsound API `World::components_mut`: ```rust use bevy_ecs::prelude::*; #[derive(Component)] struct Foo(u8); #[derive(Debug, Component)] struct Bar([u8; 100]); fn main() { let mut world = World::new(); let e = world.spawn().insert(Foo(0)).id(); *world.components_mut() = Default::default(); let bar = world.entity_mut(e).remove::<Bar>().unwrap(); // oopsies reading memory copied from outside allocation dbg!(bar); } ```
Objective
make bevy ecs a lil bit less unsound
Solution
yeet unsound API
World::components_mut
: